dポイントプレゼントキャンペーン実施中!

xorshiftという乱数生成プログラムがあります。
この乱数の最大値が知りたいのですが、ご存じの方がいらっしゃいましたら教えてください。
unsigned long xorshiftrand(void) {
static unsigned long
x=123456789, y=362436069,
z=521288629, w=88675123;
unsigned long t;
t = x ^ (x << 11);
x = y; y = z; z = w;
return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

A 回答 (3件)

#2です。


for (i=0; i<ULONG_MAX;;++){

for (i=0; i<ULONG_MAX-1;i++){
に訂正します。
    • good
    • 0

実際にやってみました。


以下のソースで実行しました。
int main()
{
unsigned long max = 0;
unsigned long ret = 0;
unsigned inti;
for (i=0; i<ULONG_MAX;;++){
ret = xorshiftrand();
if (ret > max) max = ret;
}
printf ("i=%lu max=%lu\n",i,max);
return 0;
}
-----------------
100万回に1回最大値を印字します。
以下実行結果
i=0 max=3701687786
i=1000000 max=4294966536
i=2000000 max=4294966536
i=3000000 max=4294966536
中略
i=288000000 max=4294967292
i=289000000 max=4294967292
i=290000000 max=4294967295
i=291000000 max=4294967295
-----------------------------
32ビットの環境です。
290000000回実行すると、unsigned longの最大値
4294967295を返しています。
    • good
    • 0

unsigned long の最大値 (つまり ULONG_MAX) までいくのかな? それがいくつかはあなたの使っている環境次第

.
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!