diff options
author | 2015-12-18 08:52:34 +0000 | |
---|---|---|
committer | 2015-12-18 08:52:34 +0000 | |
commit | 040a3c72b8233fad1be1b485ca15c6439e6f3312 (patch) | |
tree | a1e6168b915cbc2572dbf3ed00fcf2283b173a92 /lib/libc/stdlib/rand.c | |
parent | Drop the now useless multicast setup comment. (diff) | |
download | wireguard-openbsd-040a3c72b8233fad1be1b485ca15c6439e6f3312.tar.xz wireguard-openbsd-040a3c72b8233fad1be1b485ca15c6439e6f3312.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 'lib/libc/stdlib/rand.c')
-rw-r--r-- | lib/libc/stdlib/rand.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c index 7054b81c647..56e672af015 100644 --- a/lib/libc/stdlib/rand.c +++ b/lib/libc/stdlib/rand.c @@ -37,7 +37,7 @@ int rand_r(u_int *seed) { *seed = *seed * 1103515245 + 12345; - return (*seed % ((u_int)RAND_MAX + 1)); + return (*seed & RAND_MAX); } DEF_WEAK(rand_r); @@ -50,7 +50,7 @@ int rand(void) { if (rand_deterministic == 0) - return (arc4random() % ((u_int)RAND_MAX + 1)); + return (arc4random() & RAND_MAX); return (rand_r(&next)); } |