aboutsummaryrefslogtreecommitdiff
path: root/sys/libkern
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2019-12-26 19:41:09 +0000
committerConrad Meyer <cem@FreeBSD.org>2019-12-26 19:41:09 +0000
commitf3bae413e9d0ee6dd48cab41fc353039d49bbde7 (patch)
treefb1b04049a78c707e9231e34cffd8a608dee56b9 /sys/libkern
parent3ee1d5bb9dc2db929b19ca59421d197153dbdc08 (diff)
downloadsrc-f3bae413e9d0ee6dd48cab41fc353039d49bbde7.tar.gz
src-f3bae413e9d0ee6dd48cab41fc353039d49bbde7.zip
random(9): Deprecate random(9), remove meaningless srandom(9)
srandom(9) is meaningless on SMP systems or any system with, say, interrupts. One could never rely on random(9) to produce a reproducible sequence of outputs on the basis of a specific srandom() seed because the global state was shared by all kernel contexts. As such, removing it is literally indistinguishable to random(9) consumers (as compared with retaining it). Mark random(9) as deprecated and slated for quick removal. This is not to say we intend to remove all fast, non-cryptographic PRNG(s) in the kernel. It/they just won't be random(9), as it exists today, in either name or implementation. Before random(9) is removed, a replacement will be provided and in-tree consumers will be converted. Note that despite the name, the random(9) interface does not bear any resemblance to random(3). Instead, it is the same crummy 1988 Park-Miller LCG used in libc rand(3).
Notes
Notes: svn path=/head/; revision=356097
Diffstat (limited to 'sys/libkern')
-rw-r--r--sys/libkern/random.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/sys/libkern/random.c b/sys/libkern/random.c
index 5f2651130ab7..e5e9de6108e1 100644
--- a/sys/libkern/random.c
+++ b/sys/libkern/random.c
@@ -34,32 +34,31 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/types.h>
#include <sys/libkern.h>
-
-#define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */
+#include <sys/systm.h>
static u_long randseed = 937186357; /* after srandom(1), NSHUFF counted */
-void
-srandom(u_long seed)
-{
- int i;
-
- randseed = seed;
- for (i = 0; i < NSHUFF; i++)
- (void)random();
-}
-
/*
* Pseudo-random number generator for perturbing the profiling clock,
* and whatever else we might use it for. The result is uniform on
* [0, 2^31 - 1].
*/
u_long
-random()
+random(void)
{
+ static bool warned = false;
+
long x, hi, lo, t;
+ /* Warn only once, or it gets very spammy. */
+ if (!warned) {
+ gone_in(13,
+ "random(9) is the obsolete Park-Miller LCG from 1988");
+ warned = true;
+ }
+
/*
* Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
* From "Random number generators: good ones are hard to find",