青春艺术字logo设计:请教个问题!

来源:百度文库 编辑:神马品牌网 时间:2024/04/30 01:51:00
srand()函数是用来干什么的阿?

srand()函数,它的原形是void srand( int a) 功能是
初始化随机产生器既rand()函数的初始值
//***********************************************
srand(seed);
然后调用rand()就可以了,相同的seed产生的随机数排列是相同的
//***********************************************
比如
srand(20);
假设调用rand()后产生随机数4,6,7,8,然后退出程序,下一次运行时产生的还是4,6,7,8
//***********************************************
要想每次运行产生不同的随机数就用srand(TIME(NULL));
记得srand()用头文件stdlib.h,TIME(NULL)用time.h
//***********************************************
另一个更方便的函数,randomize()
原形是void randomize(),功能是用来始初rand() 的种子的初始值,而且该值是不确定的,它相当于srand((unsign)(time(NULL)) 不过应注意的是randomize()的功能要通过time来实现所以在调用它时头文件要包含time.h罢了

配置随机数种子

就是生成随即数的

The srand function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand. If srand is then called with same seed value, the sequence of random numbers shall be repeated. If rand is called before any call to srand have been made, the same sequence shall be generated as when srand is first called with a seed value of 1.

配置随机数种子

就是生成随即数的