[][src]Trait rand::distributions::Distribution

pub trait Distribution<T> {
    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> T;

    fn sample_iter<'a, R>(&'a self, rng: &'a mut R) -> DistIter<'a, Self, R, T>
    where
        Self: Sized,
        R: Rng
, { ... } }

Types (distributions) that can be used to create a random instance of T.

It is possible to sample from a distribution through both the Distribution and Rng traits, via distr.sample(&mut rng) and rng.sample(distr). They also both offer the sample_iter method, which produces an iterator that samples from the distribution.

All implementations are expected to be immutable; this has the significant advantage of not needing to consider thread safety, and for most distributions efficient state-less sampling algorithms are available.

Required methods

Generate a random value of T, using rng as the source of randomness.

Loading content...

Provided methods

Important traits for DistIter<'a, D, R, T>

Create an iterator that generates random values of T, using rng as the source of randomness.

Example

use rand::thread_rng;
use rand::distributions::{Distribution, Alphanumeric, Uniform, Standard};

let mut rng = thread_rng();

// Vec of 16 x f32:
let v: Vec<f32> = Standard.sample_iter(&mut rng).take(16).collect();

// String:
let s: String = Alphanumeric.sample_iter(&mut rng).take(7).collect();

// Dice-rolling:
let die_range = Uniform::new_inclusive(1, 6);
let mut roll_die = die_range.sample_iter(&mut rng);
while roll_die.next().unwrap() != 6 {
    println!("Not a 6; rolling again!");
}
Loading content...

Implementations on Foreign Types

impl<'a, T, D: Distribution<T>> Distribution<T> for &'a D
[src]

Important traits for DistIter<'a, D, R, T>

Loading content...

Implementors

impl Distribution<[f64; 2]> for UnitCircle
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<[f64; 3]> for UnitSphereSurface
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<bool> for Bernoulli
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<bool> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<char> for Alphanumeric
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<char> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f32> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f32> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f32> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Gamma
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for ChiSquared
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for FisherF
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for StudentT
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Beta
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for StandardNormal
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Normal
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for LogNormal
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Exp
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Pareto
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Cauchy
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Triangular
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Weibull
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Exp1
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<f64> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<i128> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<i16> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<i32> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<i64> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<i8> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<isize> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<u128> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<u16> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<u32> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<u64> for Poisson
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<u64> for Binomial
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<u64> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<u8> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<()> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<usize> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Vec<f64>> for Dirichlet
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<__m128i> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<__m256i> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<__m64> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 16]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 16]>> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 16]>> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 2]>> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 2]>> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 4]>> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 4]>> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 8]>> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f32; 8]>> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 2]>> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 2]>> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 4]>> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 4]>> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 8]>> for Open01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[f64; 8]>> for OpenClosed01
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i16; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i16; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i16; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i16; 16]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i16; 32]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i32; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i32; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i32; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i32; 16]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i64; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i64; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i64; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i8; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i8; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i8; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i8; 16]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i8; 32]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[i8; 64]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u16; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u16; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u16; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u16; 16]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u16; 32]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u32; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u32; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u32; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u32; 16]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u64; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u64; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u64; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u8; 2]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u8; 4]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u8; 8]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u8; 16]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u8; 32]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl Distribution<Simd<[u8; 64]>> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl<'a, T: Clone> Distribution<T> for WeightedChoice<'a, T>
[src]

Important traits for DistIter<'a, D, R, T>

impl<A> Distribution<(A,)> for Standard where
    Standard: Distribution<A>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B> Distribution<(A, B)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C> Distribution<(A, B, C)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D> Distribution<(A, B, C, D)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E> Distribution<(A, B, C, D, E)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E, F> Distribution<(A, B, C, D, E, F)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>,
    Standard: Distribution<F>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E, F, G> Distribution<(A, B, C, D, E, F, G)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>,
    Standard: Distribution<F>,
    Standard: Distribution<G>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E, F, G, H> Distribution<(A, B, C, D, E, F, G, H)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>,
    Standard: Distribution<F>,
    Standard: Distribution<G>,
    Standard: Distribution<H>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E, F, G, H, I> Distribution<(A, B, C, D, E, F, G, H, I)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>,
    Standard: Distribution<F>,
    Standard: Distribution<G>,
    Standard: Distribution<H>,
    Standard: Distribution<I>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E, F, G, H, I, J> Distribution<(A, B, C, D, E, F, G, H, I, J)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>,
    Standard: Distribution<F>,
    Standard: Distribution<G>,
    Standard: Distribution<H>,
    Standard: Distribution<I>,
    Standard: Distribution<J>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E, F, G, H, I, J, K> Distribution<(A, B, C, D, E, F, G, H, I, J, K)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>,
    Standard: Distribution<F>,
    Standard: Distribution<G>,
    Standard: Distribution<H>,
    Standard: Distribution<I>,
    Standard: Distribution<J>,
    Standard: Distribution<K>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<A, B, C, D, E, F, G, H, I, J, K, L> Distribution<(A, B, C, D, E, F, G, H, I, J, K, L)> for Standard where
    Standard: Distribution<A>,
    Standard: Distribution<B>,
    Standard: Distribution<C>,
    Standard: Distribution<D>,
    Standard: Distribution<E>,
    Standard: Distribution<F>,
    Standard: Distribution<G>,
    Standard: Distribution<H>,
    Standard: Distribution<I>,
    Standard: Distribution<J>,
    Standard: Distribution<K>,
    Standard: Distribution<L>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<Option<T>> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 0]> for Standard
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 1]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 2]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 3]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 4]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 5]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 6]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 7]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 8]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 9]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 10]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 11]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 12]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 13]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 14]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 15]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 16]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 17]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 18]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 19]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 20]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 21]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 22]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 23]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 24]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 25]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 26]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 27]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 28]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 29]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 30]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 31]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<[T; 32]> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<T> Distribution<Wrapping<T>> for Standard where
    Standard: Distribution<T>, 
[src]

Important traits for DistIter<'a, D, R, T>

impl<X> Distribution<usize> for WeightedIndex<X> where
    X: SampleUniform + PartialOrd
[src]

Important traits for DistIter<'a, D, R, T>

impl<X: SampleUniform> Distribution<X> for Uniform<X>
[src]

Important traits for DistIter<'a, D, R, T>

Loading content...