Skip to content

Commit

Permalink
Ignore the 3 least significant bits for the ziggurat layer
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Dec 7, 2017
1 parent 3931fba commit a8641a2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ fn ziggurat<R: Rng+?Sized, P, Z>(
// 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
Expand All @@ -176,7 +178,7 @@ fn ziggurat<R: Rng+?Sized, P, Z>(
} else {
bits.closed_open01_fixed()
};
let i = (bits & 0xff) as usize;
let i = ((bits >> 3) & 0xff) as usize;

let x = u * x_tab[i];

Expand Down

0 comments on commit a8641a2

Please sign in to comment.