Skip to main content

bernoulli_packed_fast

Function bernoulli_packed_fast 

Source
pub fn bernoulli_packed_fast<R: Rng + ?Sized>(
    prob: f64,
    length: usize,
    rng: &mut R,
) -> Vec<u64>
Expand description

Fast packed Bernoulli generation using byte-threshold comparison.

Instead of generating one f64 (8 bytes) per bit and comparing, this generates one u8 (1 byte) per bit via rng.fill() and compares against a u8 threshold = (prob * 256.0) as u8.

This uses 8x less RNG bandwidth than bernoulli_packed at the cost of 8-bit probability resolution (1/256 granularity). For bitstream lengths >= 256, the statistical difference is negligible compared to inherent sampling noise.

The output is NOT bit-identical to bernoulli_packed for the same RNG state.