diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2008-06-09 23:05:43 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2008-06-09 23:05:43 +0000 |
commit | 745a31d28b64181d4545890433494283dd54cadd (patch) | |
tree | 9a24762899d4c0ba499532bfa559ad5ba6a33ec9 /usr.sbin | |
parent | e4653bcb5e394af2fef9183fcfcdd274026008e2 (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 'usr.sbin')
-rw-r--r-- | usr.sbin/bind/lib/isc/random.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.sbin/bind/lib/isc/random.c b/usr.sbin/bind/lib/isc/random.c index 0cb8a0906f5..ac9bde7b8cb 100644 --- a/usr.sbin/bind/lib/isc/random.c +++ b/usr.sbin/bind/lib/isc/random.c @@ -114,8 +114,8 @@ isc_random_uniform(isc_uint32_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 |