Index: lib/libstand/random.c =================================================================== --- lib/libstand/random.c (revision 285130) +++ lib/libstand/random.c (working copy) @@ -34,13 +34,15 @@ #include -static u_long randseed = 1; +static unsigned long seed[4] = {123456789, 362436000, 521288629, 7654321}; void -srandom(seed) - u_long seed; +srandom(u_long newseed) { - randseed = seed; + static short int randcount = 0; + seed[randcount++] = newseed; + if (randcount > 3) + randcount = 0; } /* @@ -49,22 +51,21 @@ * [0, 2^31 - 1]. */ u_long -random() +random(void) { - long x, hi, lo, t; + unsigned long long t, a = 698769069LL; /* - * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1). - * From "Random number generators: good ones are hard to find", - * Park and Miller, Communications of the ACM, vol. 31, no. 10, - * October 1988, p. 1195. + * Use George Marsaglia's 1998 KISS PRNG algorithm. + * The algorithm is not crypto-quality, but it is + * known to have a high period (about 2^123) and + * it passes all the statistical tests. */ - x = randseed; - hi = x / 127773; - lo = x % 127773; - t = 16807 * lo - 2836 * hi; - if (t <= 0) - t += 0x7fffffff; - randseed = t; - return (t); + seed[0] = 69069 * seed[0] + 12345; + seed[1] ^= (seed[1] << 13); + seed[1] ^= (seed[1] >> 17); + seed[1] ^= (seed[1] << 5); + t = a * seed[2] + seed[3]; + seed[1] = (t >> 32); + return ((seed[0] + seed[1] + (seed[3] = t)) & 0x7fffffff); }