summaryrefslogtreecommitdiff
path: root/lib/libc/gen/arc4random.c
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2008-07-22 12:43:09 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2008-07-22 12:43:09 +0000
commit61d35b63502e09897377780f0db236426da1f997 (patch)
tree5ffd58b79b3f9d9258ee560622881668e81198dc /lib/libc/gen/arc4random.c
parentc0046493c9e8056e8dd7a20c6cf436773eb706fd (diff)
Notes
Diffstat (limited to 'lib/libc/gen/arc4random.c')
-rw-r--r--lib/libc/gen/arc4random.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c
index 1c7dead160a2..56e457b8e9fb 100644
--- a/lib/libc/gen/arc4random.c
+++ b/lib/libc/gen/arc4random.c
@@ -256,7 +256,11 @@ arc4random_uniform(u_int32_t upper_bound)
u_int32_t r, min;
if (upper_bound < 2)
- return 0;
+ return (0);
+
+ /* Detect simple power of two case */
+ if ((upper_bound & -upper_bound) == upper_bound)
+ return (arc4random() % upper_bound);
#if (ULONG_MAX > 0xffffffffUL)
min = 0x100000000UL % upper_bound;