好二进制PRNG [英] Good binary PRNG

查看:60
本文介绍了好二进制PRNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用rand()和旧版本og gcc,并使用Tausworth的方法,我

在第一个数字中计算频率为0或1,如下所示:


int hist [2] = {0,0};


for(i = 0; i< 100000; ++ i)

{

++ hist [prng()%2];

}


出于某种原因,在两种情况下,0都经常发生在1以上,无论是什么种子我用来初始化prng的种子。上面的代码中有50150 vs

49850之类的东西。


有没有人知道一个好的二进制字母。 PRNG,也就是说,在

以上的情况下会产生接近50000 vs 50000的东西?


/ David

Using rand() in and old version og gcc, and using Tausworth''s method, I
calculated the frequency of 0 or 1 in the first digit like this:

int hist[2] = {0,0};

for (i = 0; i < 100000; ++i)
{
++hist[prng() % 2];
}

For some reason, in both cases, 0 occurs more often than 1, no matter
what seed I use to initialize the prng with. Something like 50150 vs
49850 in the above code.

Does anybody know of a good "binary" PRNG, that is, one that in the
above case would make something closer to 50000 vs 50000?

/David

推荐答案

pi ****** ******@gmail.com 写道:
使用rand()和旧版本og gcc,并使用Tausworth的方法,我
计算了第一个数字的频率为0或1,如下所示:

int hist [2] = {0,0};

for(i = 0; i< 100000 ; ++ i)
{
++ hist [prng()%2];
}

出于某种原因,在这两种情况下,0经常发生比1,无论是什么种子我用来初始化prng。在上面的代码中有类似50150 vs
49850的内容。

有人知道一个好的二进制吗? PRNG,也就是说,在上面的案例中会有一个接近50000 vs 50000的东西?
Using rand() in and old version og gcc, and using Tausworth''s method, I
calculated the frequency of 0 or 1 in the first digit like this:

int hist[2] = {0,0};

for (i = 0; i < 100000; ++i)
{
++hist[prng() % 2];
}

For some reason, in both cases, 0 occurs more often than 1, no matter
what seed I use to initialize the prng with. Something like 50150 vs
49850 in the above code.

Does anybody know of a good "binary" PRNG, that is, one that in the
above case would make something closer to 50000 vs 50000?




我建议你从comp.lang开始。 c如问题13.15所述的常见问题解答

我需要一个随机数发生器。您可以在
http://c-faq.com/

-

Flash Gordon,生活在有趣的时代。

网站 -
http://home.flash-gordon.me.uk/

comp.lang.c发布指南和介绍:
http://clc-wiki.net/wiki / Intro_to_clc



I suggest you start with the comp.lang.c FAQ which as question 13.15 has
"I need a random number generator". You can find the FAQ at
http://c-faq.com/
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc




< pi ************ @ gmail.com>在消息中写道

news:11 ********************** @ i40g2000cwc.googlegr oups.com ...

<pi************@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
使用rand()和旧版本og gcc,并使用Tausworth的方法,我在第一个数字中计算出0或1的频率,如下所示:

int hist [2] = {0,0};

for(i = 0; i< 100000; ++ i)
{
++ hist [prng( )%2];
}

出于某种原因,在两种情况下,0都经常发生在1以上,无论我用什么种子来初始化prng。在上面的代码中有类似50150 vs
49850的内容。

有人知道一个好的二进制吗? PRNG,也就是说,在上面的情况下会产生接近50000和50000的东西吗?
Using rand() in and old version og gcc, and using Tausworth''s method, I
calculated the frequency of 0 or 1 in the first digit like this:

int hist[2] = {0,0};

for (i = 0; i < 100000; ++i)
{
++hist[prng() % 2];
}

For some reason, in both cases, 0 occurs more often than 1, no matter
what seed I use to initialize the prng with. Something like 50150 vs
49850 in the above code.

Does anybody know of a good "binary" PRNG, that is, one that in the
above case would make something closer to 50000 vs 50000?




很多PRNG'(Mersienne Twister,ISO C等似乎打了二进制甜蜜的

现货。在调用rand()大约700万次之后。


使用编译器或PRNG尝试以下代码:


#include< stdio。 h>

#include< stdlib.h>

#include< time.h>


unsigned long hist [ 2] = {0,0};


int main(无效)

{

unsigned long i,value;


srand(NULL);


for(i = 0; i< 7000000; ++ i)

{

rand();

}

for(i = 0; i< 100000; ++ i)

{

value = rand();

++ hist [value%2];

}

printf("%ld%ld \ n",hist [0],hist [1]);


return(EXIT_SUCCESS);

}

Rod Pemberton



Many PRNG''s (Mersienne Twister, ISO C, etc.) seem to hit a binary "sweet
spot" after calling rand() about 7 million times.

Try the following code with your compiler or PRNG:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

unsigned long hist[2] = {0,0};

int main(void)
{
unsigned long i, value;

srand(NULL);

for (i = 0; i < 7000000; ++i)
{
rand();
}
for (i = 0; i < 100000; ++i)
{
value=rand();
++hist[value%2];
}
printf("%ld %ld\n",hist[0],hist[1]);

return(EXIT_SUCCESS);
}
Rod Pemberton


" Rod Pemberton" <做********* @ bitfoad.cmm>写道:

[...]
"Rod Pemberton" <do*********@bitfoad.cmm> writes:
[...]
srand(NULL);
srand(NULL);




srand(time(NULL) );


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



srand(time(NULL));

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于好二进制PRNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆