summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/rand.c
diff options
context:
space:
mode:
authortb <tb@openbsd.org>2015-12-18 08:52:34 +0000
committertb <tb@openbsd.org>2015-12-18 08:52:34 +0000
commit040a3c72b8233fad1be1b485ca15c6439e6f3312 (patch)
treea1e6168b915cbc2572dbf3ed00fcf2283b173a92 /lib/libc/stdlib/rand.c
parentDrop the now useless multicast setup comment. (diff)
downloadwireguard-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.c4
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));
}