diff options
Diffstat (limited to 'src/lib/libc/stdlib/rand.c')
-rw-r--r-- | src/lib/libc/stdlib/rand.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c index 361d473448..bb180886c0 100644 --- a/src/lib/libc/stdlib/rand.c +++ b/src/lib/libc/stdlib/rand.c | |||
@@ -32,24 +32,34 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)rand.c 5.6 (Berkeley) 6/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: rand.c,v 1.6 1998/12/07 21:47:22 millert Exp $"; |
36 | static 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <sys/types.h> | 38 | #include <sys/types.h> |
40 | #include <stdlib.h> | 39 | #include <stdlib.h> |
41 | 40 | ||
42 | static u_long next = 1; | 41 | static u_int next = 1; |
42 | |||
43 | int | ||
44 | rand_r(seed) | ||
45 | u_int *seed; | ||
46 | { | ||
47 | |||
48 | *seed = *seed * 1103515245 + 12345; | ||
49 | return (*seed % ((u_int)RAND_MAX + 1)); | ||
50 | } | ||
43 | 51 | ||
44 | int | 52 | int |
45 | rand() | 53 | rand() |
46 | { | 54 | { |
47 | return ((next = next * 1103515245 + 12345) % ((u_int)RAND_MAX + 1)); | 55 | |
56 | return (rand_r(&next)); | ||
48 | } | 57 | } |
49 | 58 | ||
50 | void | 59 | void |
51 | srand(seed) | 60 | srand(seed) |
52 | u_int seed; | 61 | u_int seed; |
53 | { | 62 | { |
63 | |||
54 | next = seed; | 64 | next = seed; |
55 | } | 65 | } |