summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/rand.c')
-rw-r--r--src/lib/libc/stdlib/rand.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c
index 361d473448..6860dd4f71 100644
--- a/src/lib/libc/stdlib/rand.c
+++ b/src/lib/libc/stdlib/rand.c
@@ -10,11 +10,7 @@
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software 13 * 3. Neither the name of the University nor the names of its contributors
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software 14 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission. 15 * without specific prior written permission.
20 * 16 *
@@ -31,25 +27,41 @@
31 * SUCH DAMAGE. 27 * SUCH DAMAGE.
32 */ 28 */
33 29
34#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)rand.c 5.6 (Berkeley) 6/24/91";*/
36static char *rcsid = "$Id: rand.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $";
37#endif /* LIBC_SCCS and not lint */
38
39#include <sys/types.h> 30#include <sys/types.h>
40#include <stdlib.h> 31#include <stdlib.h>
41 32
42static u_long next = 1; 33static u_int next = 1;
34
35int
36rand_r(u_int *seed)
37{
38 *seed = *seed * 1103515245 + 12345;
39 return (*seed % ((u_int)RAND_MAX + 1));
40}
41
42#if defined(APIWARN)
43__warn_references(rand_r,
44 "warning: rand_r() isn't random; consider using arc4random()");
45#endif
43 46
44int 47int
45rand() 48rand(void)
46{ 49{
47 return ((next = next * 1103515245 + 12345) % ((u_int)RAND_MAX + 1)); 50 return (rand_r(&next));
48} 51}
49 52
53#if defined(APIWARN)
54__warn_references(rand,
55 "warning: rand() isn't random; consider using arc4random()");
56#endif
57
50void 58void
51srand(seed) 59srand(u_int seed)
52u_int seed;
53{ 60{
54 next = seed; 61 next = seed;
55} 62}
63
64#if defined(APIWARN)
65__warn_references(srand,
66 "warning: srand() seed choices are invariably poor");
67#endif