Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/rand_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ impl Rand for char {
impl Rand for bool {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> bool {
rng.gen::<u8>() & 1 == 1
// Generate a 32-bit value and test the sign.
// Many PRNGs exhibit non-uniform random quality across their bits. The
// low order bit of LCGs, for example, flips 0/1. Even some high
// quality PRNGs, like Xoroshiro128+, have strange low order bit
// behavior. Testing the sign offers protection against these common
// pathologies.
rng.gen::<i32>() < 0
}
}

Expand Down