Algorithm Implementation/Pseudorandom Numbers/Linear congruential generator

From Wikibooks, open books for an open world
Jump to navigation Jump to search

C[edit]

#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;
}