这个你在哪里看到的?rand()在很多系统上最大只返回三万多,%100000000有什么意义?
而且rand()函数在很多系统上实现都有低字节随机度不够的问题。man rand明确说了:
In Numerical Recipes in C: The Art of Scientific Computing (William H.
Press, Brian P. Flannery, Saul A. Teukolsky, William T. Vetterling;
New York: Cambridge University Press, 1992 (2nd ed., p. 277)), the
following comments are made:
"If you want to generate a random integer between 1 and 10, you
should always do it by using high-order bits, as in
j=1+(int) (10.0*rand()/(RAND_MAX+1.0));
and never by anything resembling
j=1+(rand() % 10);
(which uses lower-order bits)."
【 在 yanzg (油炸鬼~新家~项王) 的大作中提到: 】
: 居然发现了
: rand() % 100000000
: 看来我可以放心用了。
: ...................
--
FROM 128.12.181.*