其中有位老兄阿容说的很对;"非常可惜的告诉你,虽然看起来更象真随机数,但是只要是计算机软件产生的,就绝对不可能是真随机数。所以这种说法是有问题的"
但有解决的办法,能产生真正的随机数,就是利用噪音技术perlin noise参考文献
( luoshenghua2003 发表于 2006-12-19 13:56:00)
从帮助文档中可以知道得很清楚
测试:
#include
#include
#include
void main()
{
srand(1);
printf("%d\n",rand());
printf("%d\n",rand());
srand(1);
printf("%d\n",rand());
printf("%d\n",rand());
}
两次产生的随机数相同,证实了“The srand function sets the starting point for generating a series of pseudorandom integers”
( vspath 发表于 2004-5-26 14:13:00)
rand
Generates a pseudorandom number.
int rand( void );
Return Value
rand returns a pseudorandom number, as described above. There is no error return.
Remarks
The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand
Remarks
The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.
( vspath 发表于 2004-5-26 14:13:00)
#include
#include
#include
int x;
void main(){
srand( (unsigned)time( NULL ) );
for(int i=0;i<1000;i++){
x=rand()%13;//返回一个0-12的随机数...
cout<}
//这下在试试 ( smile00001 发表于 2003-5-25 21:15:00)
非常可惜的告诉你,虽然看起来更象真随机数,但是只要是计算机软件产生的,就绝对不可能是真随机数。所以这种说法是有问题的。 ( 阿荣 发表于 2003-3-28 21:37:00)
偶是初学,在书上看到过您的这种做法,但是有一些疑问:1。所谓种子是什么意思?2。time函数的参数起什么作用的?3。哪里能查到函数的源代码或者大部分函数功能的详细介绍?谢谢 ( rocku 发表于 2003-2-10 23:59:00)
我在编俄罗斯方块时也遇到了同样的问题,也是借用time来随机第一次的方块,但你这样的方法我还没试过。 ( givemore 发表于 2003-2-3 18:40:00)
直接用rand()%a+b格式不可以吗???? ( livemumu 发表于 2002-12-25 19:30:00)
前面不加 srand()好象也可以产生随机数,对吗? ( 阿飞 发表于 2002-10-24 16:33:00)
对随机数的各种处理,模拟了许多现实生活中很难解决的问题。 ( 王骏 发表于 2002-10-7 10:28:00)
.......................................................
--------------------next---------------------
阅读(263) | 评论(0) | 转发(0) |