跳转至内容

算法实现/伪随机数字/线性同余发生器

来自 Wikibooks,一个开放世界的开放书籍
#define RAND_MAX 32768

static unsigned long int next = 1;

int lcg(void)
{
	next = next * 1103515245 + 12345;
	return (unsigned int) (next / 65536) % RAND_MAX;
}

void slcg(unsigned int seed)
{
	next = seed;
}
华夏公益教科书