aboutsummaryrefslogtreecommitdiff
path: root/compat/arc4random_uniform.c
diff options
context:
space:
mode:
Diffstat (limited to 'compat/arc4random_uniform.c')
-rw-r--r--compat/arc4random_uniform.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/compat/arc4random_uniform.c b/compat/arc4random_uniform.c
index 0f1b7b296759..4511722909b3 100644
--- a/compat/arc4random_uniform.c
+++ b/compat/arc4random_uniform.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $ */
+
/*
* Copyright (c) 2008, Damien Miller <djm@openbsd.org>
*
@@ -48,9 +50,11 @@ arc4random_uniform(uint32_t upper_bound)
* number inside the range we need, so it should rarely need
* to re-roll.
*/
- do
+ for (;;) {
r = arc4random();
- while (r < min);
+ if (r >= min)
+ break;
+ }
return r % upper_bound;
}