File:  [MW Coherent from dump] / coherent / b / lib / libc / gen / rand.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:35 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * Random number generator, of period 2 ^ 32. Returns random numbers (ints) in
 *	the interval [0, 2^15-1].
 * The algorithm used is a linear congruential method, where the internal
 *	computation is done in unsigned longs (mod 2^32). The numbers from
 *	this sequence are right shifted 17 bits so that the most random 15
 *	bits are returned.
 * All this is from Knuth Vol 2, 2nd ed., ch 3. The choice of multiplier
 *	is made from the table in 3.3.4.E,  pp102.
 */

#define	A	1664525L		/* Multiplicative generator */
#define	C	907633387L		/* Additive generator */


static long	seed	= 1;

srand(n)
unsigned int n;
{
	seed = n;
}

rand()
{
	seed = seed * A + C;
	return ((seed >> 17) & 077777);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.