pub struct UniformU64Sampler { /* private fields */ }Expand description
Compatibility uniform range [0, limit) sampler for u64 numbers
Sampler uses provided rand::Rng reference to generate random u64 numbers and
map them to desired range maintaining uniform distribution of generated numbers.
This utility exists only to provide compatibility of sampling algorithm with rand
library at versions <=0.8.5, since parts of the system rely on reproducible sequence
of numbers given stable seeded random number generator.
Two sampling algorithms are supported (they initialize internal zone value in different ways)
to provide compatibility with two ways rand sampling can be performed:
new_like_instance_sample: reproduces values obtained from sampler instance created withrand::distributions::uniform::UniformSampler::newand then used by callingsamplenew_like_trait_sample: reproduces values obtained from trait function callsrand::distributions::uniform::UniformSampler::sample_single
Implementations§
Source§impl UniformU64Sampler
impl UniformU64Sampler
Sourcepub fn new_like_instance_sample(range_end: NonZero<u64>) -> Self
pub fn new_like_instance_sample(range_end: NonZero<u64>) -> Self
Create sampler reproducing sample calls on UniformInt instance
The zone internal threshold is obtained by calculating modulo of u64::MAX’s difference
with provided range’s end to itself. See:
https://github.com/rust-random/rand/blob/937320cbfeebd4352a23086d9c6e68f067f74644/src/distributions/uniform.rs#L458-L504
Sourcepub fn new_like_trait_sample(range_end: NonZero<u64>) -> Self
pub fn new_like_trait_sample(range_end: NonZero<u64>) -> Self
Create sampler reproducing direct sample_single calls on UniformInt trait
The zone internal threshold is obtained by calculating 2^{number of leading zeros in provided range}. See
https://github.com/rust-random/rand/blob/937320cbfeebd4352a23086d9c6e68f067f74644/src/distributions/uniform.rs#L534-L553