From 90b17882f1fdf22d73b3ce2343f36adb6e534a87 Mon Sep 17 00:00:00 2001 From: tb <> Date: Fri, 18 Dec 2015 08:52:34 +0000 Subject: [PATCH] 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@ --- src/lib/libc/stdlib/rand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c index 7054b81c..56e672af 100644 --- a/src/lib/libc/stdlib/rand.c +++ b/src/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)); }