随机函数(stdlib)

来源:互联网 发布:linux编辑文件命令vim 编辑:程序博客网 时间:2024/06/05 10:16

The following code defines a pair of functions which could be incorporated into applications wishing to ensure that the same sequence of numbers is generated across different machines:

下面的代码,在种子值相同的情况下,即使是在不同的机器上也可以产生相同的序列值

static unsigned long int next = 1;int myrand(void)    /* RAND_MAX assumed to be 32767 */{    next = next * 1103515245 + 12345;    return((unsigned int)(next/65536) % 32768);}void mysrand(unsigned int seed){    next = seed;}

 

详见

http://pubs.opengroup.org/onlinepubs/7908799/xsh/rand.html

原创粉丝点击