Trait rand::distributions::uniform::UniformSampler
source · [−]pub trait UniformSampler: Sized {
type X;
fn new<B1, B2>(low: B1, high: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized;
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized;
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X;
fn sample_single<R: Rng + ?Sized, B1, B2>(
low: B1,
high: B2,
rng: &mut R
) -> Self::X
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
{ ... }
}Expand description
Helper trait handling actual uniform sampling.
See the module documentation on how to implement Uniform range
sampling for a custom type.
Implementation of sample_single is optional, and is only useful when
the implementation can be faster than Self::new(low, high).sample(rng).
Associated Types
Required methods
fn new<B1, B2>(low: B1, high: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
fn new<B1, B2>(low: B1, high: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
Construct self, with inclusive lower bound and exclusive upper bound
[low, high).
Usually users should not call this directly but instead use
Uniform::new, which asserts that low < high before calling this.
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
Construct self, with inclusive bounds [low, high].
Usually users should not call this directly but instead use
Uniform::new_inclusive, which asserts that low <= high before
calling this.
Provided methods
fn sample_single<R: Rng + ?Sized, B1, B2>(
low: B1,
high: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
fn sample_single<R: Rng + ?Sized, B1, B2>(
low: B1,
high: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
Sample a single value uniformly from a range with inclusive lower bound
and exclusive upper bound [low, high).
Usually users should not call this directly but instead use
Uniform::sample_single, which asserts that low < high before calling
this.
Via this method, implementations can provide a method optimized for
sampling only a single value from the specified range. The default
implementation simply calls UniformSampler::new then sample on the
result.
