From 9acffc01060b6037f6e8b3ae5bb849752e2d0d75 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 19 Aug 2010 14:53:42 +0200 Subject: [PATCH] fast_irandom(): Fix an off-by-one error in case of max=2^n --- random.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/random.h b/random.h index 2c34a99..fe351c4 100644 --- a/random.h +++ b/random.h @@ -20,7 +20,7 @@ fast_irandom(unsigned int max) { if (max <= 65536) return fast_random(max); - int himax = max / 65536; + int himax = (max - 1) / 65536; uint16_t hi = fast_random(himax + 1); return ((uint32_t)hi << 16) | fast_random(hi < himax ? 65536 : max % 65536); } -- 2.11.4.GIT