Skip to main content

UniformU64Sampler

Struct UniformU64Sampler 

Source
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 with rand::distributions::uniform::UniformSampler::new and then used by calling sample
  • new_like_trait_sample: reproduces values obtained from trait function calls rand::distributions::uniform::UniformSampler::sample_single

Implementations§

Source§

impl UniformU64Sampler

Source

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

Source

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

Source

pub fn sample(&self, rng: &mut impl Rng) -> u64

Obtain random number from rng and map it to the initialized range of this sampler

Trait Implementations§

Source§

impl Debug for UniformU64Sampler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V