summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2008-06-09 23:03:17 +0000
committerDamien Miller <djm@cvs.openbsd.org>2008-06-09 23:03:17 +0000
commite4653bcb5e394af2fef9183fcfcdd274026008e2 (patch)
treee7ca6f537257cda88dcd355e86aa012bab751c0d /sys/dev
parent30f01995f888bdaa1f410d587f267d24dd4412f2 (diff)
simplify math for arc4random_uniform() suggested by
Jinmei_Tatuya AT isc.org via jakob@ empirically verified for entire domain of upper_bound
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/rnd.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c
index 328919de450..15a5e0543f2 100644
--- a/sys/dev/rnd.c
+++ b/sys/dev/rnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rnd.c,v 1.89 2008/06/09 07:07:16 djm Exp $ */
+/* $OpenBSD: rnd.c,v 1.90 2008/06/09 23:03:16 djm Exp $ */
/*
* rnd.c -- A strong random number generator
@@ -625,8 +625,8 @@ arc4random_uniform(u_int32_t upper_bound)
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;
+ /* (2**32 - x) % x == 2**32 % x when x <= 2**31 */
+ min = ((0xffffffff - upper_bound) + 1) % upper_bound;
}
#endif