X



疑似乱数2

■ このスレッドは過去ログ倉庫に格納されています
1デフォルトの名無しさん
垢版 |
2007/10/17(水) 22:34:59
擬似乱数発生器について語ろうか。その2

前スレ
擬似乱数
http://pc11.2ch.net/test/read.cgi/tech/1146071975/

関連スレ
【危険】とんでもプログラム告発スレッド【悪質】
http://pc11.2ch.net/test/read.cgi/tech/1191860116/


SIMD-oriented Fast Mersenne Twister (SFMT):
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html
2007/11/02(金) 15:50:53
ド素人なので突っ込みどころがあったら御教授くださいorz
rand()で生成した乱数をバイナリ形式で出力して
NIST SP800-22やdiehardテストに突っ込みたいんですけど・・・

↓のままだとdiehardどころかSP800-22にも引っかかってしまいます
#include <stdio.h>
#include <stdlib.h> // rand, srand使用
#include <time.h> // time使用
#define size 12000000 //bit列の長さ定義

2007/11/02(金) 15:52:35
main()
{
FILE *outputfile; // 出力ストリーム
unsigned long int m,i=0;
char bit[size];
srand((unsigned) time(NULL)); // time関数からシードをセット
outputfile = fopen("bit.dat", "w"); // ファイルを書き込み用にオープン
if (outputfile == NULL) { // オープンに失敗した場合
printf("cannot open\n"); // エラーメッセージを出して
exit(1); // 異常終了
}
for(i=0; i<size-1; i++){ // 乱数を発生させ剰余を計算
m=rand()%0xffff;
bit[i]=m;
}
fwrite(&bit,size,1,outputfile); //バイナリの書き込み
fclose(outputfile); // ファイルをクローズ
return 0;
}

↓公式ページ
NIST ttp://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html
diehard ttp://stat.fsu.edu/pub/diehard/
■ このスレッドは過去ログ倉庫に格納されています
5ちゃんねるの広告が気に入らない場合は、こちらをクリックしてください。

ニューススポーツなんでも実況