Jump to content

Algorithm Implementation/Pseudorandom Numbers/Linear congruential generator

From Wikibooks, open books for an open world
#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;
}