[−][src]Trait rand::distributions::uniform::UniformSampler
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
type X
The type sampled by this implementation.
Required Methods
fn new(low: Self::X, high: Self::X) -> Self
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(low: Self::X, high: Self::X) -> Self
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.
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
Sample a value.
Provided Methods
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
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.
Implementors
impl UniformSampler for UniformDuration
[src]
impl UniformSampler for UniformDuration
type X = Duration
fn new(low: Duration, high: Duration) -> UniformDuration
[src]
fn new(low: Duration, high: Duration) -> UniformDuration
fn new_inclusive(low: Duration, high: Duration) -> UniformDuration
[src]
fn new_inclusive(low: Duration, high: Duration) -> UniformDuration
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Duration
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Duration
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformFloat<f32>
[src]
impl UniformSampler for UniformFloat<f32>
type X = f32
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformFloat<f64>
[src]
impl UniformSampler for UniformFloat<f64>
type X = f64
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<i16>
[src]
impl UniformSampler for UniformInt<i16>
type X = i16
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<i32>
[src]
impl UniformSampler for UniformInt<i32>
type X = i32
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<i64>
[src]
impl UniformSampler for UniformInt<i64>
type X = i64
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<i8>
[src]
impl UniformSampler for UniformInt<i8>
type X = i8
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<isize>
[src]
impl UniformSampler for UniformInt<isize>
type X = isize
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<u16>
[src]
impl UniformSampler for UniformInt<u16>
type X = u16
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<u32>
[src]
impl UniformSampler for UniformInt<u32>
type X = u32
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<u64>
[src]
impl UniformSampler for UniformInt<u64>
type X = u64
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<u8>
[src]
impl UniformSampler for UniformInt<u8>
type X = u8
fn new(low: Self::X, high: Self::X) -> Self
[src]
fn new(low: Self::X, high: Self::X) -> Self
fn new_inclusive(low: Self::X, high: Self::X) -> Self
[src]
fn new_inclusive(low: Self::X, high: Self::X) -> Self
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
[src]
fn sample_single<R: Rng + ?Sized>(
low: Self::X,
high: Self::X,
rng: &mut R
) -> Self::X
impl UniformSampler for UniformInt<usize>
[src]
impl UniformSampler for UniformInt<usize>