Chinaunix首页 | 论坛 | 博客
  • 博客访问: 379282
  • 博文数量: 715
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:46
文章分类

全部博文(715)

文章存档

2011年(1)

2008年(714)

我的朋友

分类:

2008-10-13 16:35:45

cool:不错!
(发表于2002-7-8 20:27:00)

小龙:随机数必须有自己的值作为随即种子
种子不同才能作出真正的随机数
用时间作种子时期中的一种最常用的方法
(发表于2002-7-24 22:11:00)

王骏:对随机数的各种处理,模拟了许多现实生活中很难解决的问题。
(发表于2002-10-7 10:28:00)

阿飞:前面不加 srand()好象也可以产生随机数,对吗?
(发表于2002-10-24 16:33:00)

livemumu:直接用rand()%a+b格式不可以吗????
(发表于2002-12-25 19:30:00)

givemore:我在编俄罗斯方块时也遇到了同样的问题,也是借用time来随机第一次的方块,但你这样的方法我还没试过。
(发表于2003-2-3 18:40:00)

rocku:偶是初学,在书上看到过您的这种做法,但是有一些疑问:1。所谓种子是什么意思?2。time函数的参数起什么作用的?3。哪里能查到函数的源代码或者大部分函数功能的详细介绍?谢谢
(发表于2003-2-10 23:59:00)

阿荣:非常可惜的告诉你,虽然看起来更象真随机数,但是只要是计算机软件产生的,就绝对不可能是真随机数。所以这种说法是有问题的。
(发表于2003-3-28 21:37:00)

smile00001:#include
#include
#include
int x;
void main(){
     srand( (unsigned)time( NULL ) ); 
  for(int i=0;i<1000;i++){
  x=rand()%13;//返回一个0-12的随机数... 
   cout<}
//这下在试试
(发表于2003-5-25 21:15:00)

vspath: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.


(发表于2004-5-26 14:13:00)

vspath:从帮助文档中可以知道得很清楚
测试:
#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”

(发表于2004-5-26 14:13:00)

luoshenghua2003:其中有位老兄阿容说的很对;"非常可惜的告诉你,虽然看起来更象真随机数,但是只要是计算机软件产生的,就绝对不可能是真随机数。所以这种说法是有问题的"
但有解决的办法,能产生真正的随机数,就是利用噪音技术perlin noise参考文献

(发表于2006-12-19 13:56:00)

..........................................................................
--------------------next---------------------

阅读(142) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~