summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arc4random.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/arc4random.c b/arc4random.c
index b3ec7655..21a12755 100644
--- a/arc4random.c
+++ b/arc4random.c
@@ -506,17 +506,8 @@ arc4random_uniform(unsigned int upper_bound)
if (upper_bound < 2)
return 0;
-#if (UINT_MAX > 0xffffffffUL)
- min = 0x100000000UL % upper_bound;
-#else
- /* Calculate (2**32 % upper_bound) avoiding 64-bit math */
- if (upper_bound > 0x80000000)
- min = 1 + ~upper_bound; /* 2**32 - upper_bound */
- else {
- /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
- min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
- }
-#endif
+ /* 2**32 % x == (2**32 - x) % x */
+ min = -upper_bound % upper_bound;
/*
* This could theoretically loop forever but each retry has