random.c (f3bae413e9d0ee6dd48cab41fc353039d49bbde7) random.c (8a0edc914ffdda876987add5128da3ee236a6a12)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 22 unchanged lines hidden (view full) ---

31 * @(#)random.c 8.1 (Berkeley) 6/10/93
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD$");
36
37#include <sys/types.h>
38#include <sys/libkern.h>
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 22 unchanged lines hidden (view full) ---

31 * @(#)random.c 8.1 (Berkeley) 6/10/93
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD$");
36
37#include <sys/types.h>
38#include <sys/libkern.h>
39#include <sys/prng.h>
39#include <sys/systm.h>
40
40#include <sys/systm.h>
41
41static u_long randseed = 937186357; /* after srandom(1), NSHUFF counted */
42
43/*
42/*
44 * Pseudo-random number generator for perturbing the profiling clock,
45 * and whatever else we might use it for. The result is uniform on
46 * [0, 2^31 - 1].
43 * Pseudo-random number generator. The result is uniform in [0, 2^31 - 1].
47 */
48u_long
49random(void)
50{
44 */
45u_long
46random(void)
47{
51 static bool warned = false;
52
53 long x, hi, lo, t;
54
55 /* Warn only once, or it gets very spammy. */
56 if (!warned) {
57 gone_in(13,
58 "random(9) is the obsolete Park-Miller LCG from 1988");
59 warned = true;
60 }
61
62 /*
63 * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
64 * From "Random number generators: good ones are hard to find",
65 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
66 * October 1988, p. 1195.
67 */
68 /* Can't be initialized with 0, so use another value. */
69 if ((x = randseed) == 0)
70 x = 123459876;
71 hi = x / 127773;
72 lo = x % 127773;
73 t = 16807 * lo - 2836 * hi;
74 if (t < 0)
75 t += 0x7fffffff;
76 randseed = t;
77 return (t);
48 return (prng32());
78}
49}