diff options
Diffstat (limited to 'src/lib/libc/stdlib/rand.c')
-rw-r--r-- | src/lib/libc/stdlib/rand.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c index 6860dd4f71..618559fd9c 100644 --- a/src/lib/libc/stdlib/rand.c +++ b/src/lib/libc/stdlib/rand.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | 32 | ||
33 | static int rand_deterministic; | ||
33 | static u_int next = 1; | 34 | static u_int next = 1; |
34 | 35 | ||
35 | int | 36 | int |
@@ -47,6 +48,8 @@ __warn_references(rand_r, | |||
47 | int | 48 | int |
48 | rand(void) | 49 | rand(void) |
49 | { | 50 | { |
51 | if (rand_deterministic) | ||
52 | return (arc4random() % ((u_int)RAND_MAX + 1)); | ||
50 | return (rand_r(&next)); | 53 | return (rand_r(&next)); |
51 | } | 54 | } |
52 | 55 | ||
@@ -58,10 +61,12 @@ __warn_references(rand, | |||
58 | void | 61 | void |
59 | srand(u_int seed) | 62 | srand(u_int seed) |
60 | { | 63 | { |
61 | next = seed; | 64 | rand_deterministic = 0; |
62 | } | 65 | } |
63 | 66 | ||
64 | #if defined(APIWARN) | 67 | void |
65 | __warn_references(srand, | 68 | srand_deterministic(u_int seed) |
66 | "warning: srand() seed choices are invariably poor"); | 69 | { |
67 | #endif | 70 | rand_deterministic = 1; |
71 | next = seed; | ||
72 | } | ||