diff options
author | tb <> | 2015-12-18 08:52:34 +0000 |
---|---|---|
committer | tb <> | 2015-12-18 08:52:34 +0000 |
commit | c7a8e75acdb875a1202fe9fcd79e35d82382797c (patch) | |
tree | 5f0658b997ec76e0c949f0a7fc7df4486ae7df6c /src/lib/libc/stdlib/rand.c | |
parent | 81a8c3193dfbd2174f269231d18c8c051ab1b340 (diff) | |
download | openbsd-c7a8e75acdb875a1202fe9fcd79e35d82382797c.tar.gz openbsd-c7a8e75acdb875a1202fe9fcd79e35d82382797c.tar.bz2 openbsd-c7a8e75acdb875a1202fe9fcd79e35d82382797c.zip |
Simplify return call of rand() and rand_r() to make it easier to read.
This is slightly less robust, but RAND_MAX must be one below a power
of two in both variants anyway.
Based on a suggestion by Matthew Martin.
ok tedu@
Diffstat (limited to '')
-rw-r--r-- | src/lib/libc/stdlib/rand.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c index 7054b81c64..56e672af01 100644 --- a/src/lib/libc/stdlib/rand.c +++ b/src/lib/libc/stdlib/rand.c | |||
@@ -37,7 +37,7 @@ int | |||
37 | rand_r(u_int *seed) | 37 | rand_r(u_int *seed) |
38 | { | 38 | { |
39 | *seed = *seed * 1103515245 + 12345; | 39 | *seed = *seed * 1103515245 + 12345; |
40 | return (*seed % ((u_int)RAND_MAX + 1)); | 40 | return (*seed & RAND_MAX); |
41 | } | 41 | } |
42 | DEF_WEAK(rand_r); | 42 | DEF_WEAK(rand_r); |
43 | 43 | ||
@@ -50,7 +50,7 @@ int | |||
50 | rand(void) | 50 | rand(void) |
51 | { | 51 | { |
52 | if (rand_deterministic == 0) | 52 | if (rand_deterministic == 0) |
53 | return (arc4random() % ((u_int)RAND_MAX + 1)); | 53 | return (arc4random() & RAND_MAX); |
54 | return (rand_r(&next)); | 54 | return (rand_r(&next)); |
55 | } | 55 | } |
56 | 56 | ||