summaryrefslogtreecommitdiffstats
path: root/sys/lib/libkern/random.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-08-10 21:41:08 +0000
committerderaadt <deraadt@openbsd.org>1996-08-10 21:41:08 +0000
commit9d9e279b041a9bb2d1430043f2cb5fecc6cb6e0f (patch)
tree43d7f843f22167be86eb35696f2ebea8970168cd /sys/lib/libkern/random.c
parentcall bindresvport() instead of faking it badly (diff)
downloadwireguard-openbsd-9d9e279b041a9bb2d1430043f2cb5fecc6cb6e0f.tar.xz
wireguard-openbsd-9d9e279b041a9bb2d1430043f2cb5fecc6cb6e0f.zip
srandom() seeds random() at boottime
Diffstat (limited to 'sys/lib/libkern/random.c')
-rw-r--r--sys/lib/libkern/random.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/sys/lib/libkern/random.c b/sys/lib/libkern/random.c
index 14a10320f63..970cbf4bc6c 100644
--- a/sys/lib/libkern/random.c
+++ b/sys/lib/libkern/random.c
@@ -42,10 +42,11 @@
* and whatever else we might use it for. The result is uniform on
* [0, 2^31 - 1].
*/
+u_long __randseed = 1;
+
u_long
random()
{
- static u_long randseed = 1;
register long x, hi, lo, t;
/*
@@ -54,12 +55,12 @@ random()
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
* October 1988, p. 1195.
*/
- x = randseed;
+ x = __randseed;
hi = x / 127773;
lo = x % 127773;
t = 16807 * lo - 2836 * hi;
if (t <= 0)
t += 0x7fffffff;
- randseed = t;
+ __randseed = t;
return (t);
}