随机函数(stdlib)

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

你可能感兴趣的:(随机函数(stdlib))