[][src]Trait nannou::rand::distributions::uniform::UniformSampler

pub trait UniformSampler {
    type X;
    fn new<B1, B2>(low: B1, high: B2) -> Self
    where
        B1: SampleBorrow<Self::X>,
        B2: SampleBorrow<Self::X>
;
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
    where
        B1: SampleBorrow<Self::X>,
        B2: SampleBorrow<Self::X>
;
fn sample<R>(&self, rng: &mut R) -> Self::X
    where
        R: Rng + ?Sized
; fn sample_single<R, B1, B2>(low: B1, high: B2, rng: &mut R) -> Self::X
    where
        B1: SampleBorrow<Self::X>,
        B2: SampleBorrow<Self::X>,
        R: Rng + ?Sized
, { ... } }

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.

Loading content...

Required methods

fn new<B1, B2>(low: B1, high: B2) -> Self where
    B1: SampleBorrow<Self::X>,
    B2: SampleBorrow<Self::X>, 

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>,
    B2: SampleBorrow<Self::X>, 

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>(&self, rng: &mut R) -> Self::X where
    R: Rng + ?Sized

Sample a value.

Loading content...

Provided methods

fn sample_single<R, B1, B2>(low: B1, high: B2, rng: &mut R) -> Self::X where
    B1: SampleBorrow<Self::X>,
    B2: SampleBorrow<Self::X>,
    R: Rng + ?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.

Loading content...

Implementors

impl UniformSampler for UniformDuration[src]

type X = Duration

fn sample_single<R, B1, B2>(low: B1, high: B2, rng: &mut R) -> Self::X where
    B1: SampleBorrow<Self::X>,
    B2: SampleBorrow<Self::X>,
    R: Rng + ?Sized
[src]

impl UniformSampler for UniformFloat<f32>[src]

type X = f32

impl UniformSampler for UniformFloat<f64>[src]

type X = f64

impl UniformSampler for UniformInt<i128>[src]

type X = i128

impl UniformSampler for UniformInt<i16>[src]

type X = i16

impl UniformSampler for UniformInt<i32>[src]

type X = i32

impl UniformSampler for UniformInt<i64>[src]

type X = i64

impl UniformSampler for UniformInt<i8>[src]

type X = i8

impl UniformSampler for UniformInt<isize>[src]

type X = isize

impl UniformSampler for UniformInt<u128>[src]

type X = u128

impl UniformSampler for UniformInt<u16>[src]

type X = u16

impl UniformSampler for UniformInt<u32>[src]

type X = u32

impl UniformSampler for UniformInt<u64>[src]

type X = u64

impl UniformSampler for UniformInt<u8>[src]

type X = u8

impl UniformSampler for UniformInt<usize>[src]

type X = usize

Loading content...