From a8641a2a049ccb2c791a22bf1a510faadd8d8aaf Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Thu, 7 Dec 2017 20:40:00 +0100 Subject: [PATCH] Ignore the 3 least significant bits for the ziggurat layer --- src/distributions/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/distributions/mod.rs b/src/distributions/mod.rs index 2f5573a40d2..4c93fe5cc04 100644 --- a/src/distributions/mod.rs +++ b/src/distributions/mod.rs @@ -165,6 +165,8 @@ fn ziggurat( // Of the remaining 11 least significant bits we use 8 to construct `i`. // This saves us generating a whole extra random number, while the added // precision of using 64 bits for f64 does not buy us much. + // Because for some RNG's the least significant bits can be of lower + // statistical quality, we use bits 3..10 for i. let bits: u64 = uniform(rng); // u is either U(-1, 1) or U(0, 1) depending on if this is a @@ -176,7 +178,7 @@ fn ziggurat( } else { bits.closed_open01_fixed() }; - let i = (bits & 0xff) as usize; + let i = ((bits >> 3) & 0xff) as usize; let x = u * x_tab[i];