multicast changes from lbl
[unix-history] / usr / src / sys / libkern / random.c
CommitLineData
a4681977
CT
1/*-
2 * Copyright (c) 1992 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)random.c 7.1 (Berkeley) %G%
8 */
9
10#include "libkern.h"
11
12/*
13 * Pseudo-random number generator for randomizing the profiling clock,
14 * and whatever else we might use it for. The result is uniform on
15 * [0, 2^31 - 1].
16 */
17u_long
18random()
19{
20 static u_long randseed = 1;
21 register long x, hi, lo, t;
22
23 /*
24 * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
25 * From "Random number generators: good ones are hard to find",
26 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
27 * October 1988, p. 1195.
28 */
29 x = randseed;
30 hi = x / 127773;
31 lo = x % 127773;
32 t = 16807 * lo - 2836 * hi;
33 if (t <= 0)
34 t += 0x7fffffff;
35 randseed = t;
36 return (t);
37}