Trait sprs_rand::rand::distributions::Distribution [−][src]
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.
Implementations are typically expected to be portable with reproducible
results when used with a PRNG with fixed seed; see the
portability chapter
of The Rust Rand Book. In some cases this does not apply, e.g. the usize
type requires different sampling on 32-bit and 64-bit machines.
Required methods
pub fn sample<R>(&self, rng: &mut R) -> T where
R: Rng + ?Sized,
[src]
R: Rng + ?Sized,
Generate a random value of T
, using rng
as the source of randomness.
Provided methods
pub fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>ⓘ where
R: Rng,
[src]
R: Rng,
Create an iterator that generates random values of T
, using rng
as
the source of randomness.
Note that this function takes self
by value. This works since
Distribution<T>
is impl’d for &D
where D: Distribution<T>
,
however borrowing is not automatic hence distr.sample_iter(...)
may
need to be replaced with (&distr).sample_iter(...)
to borrow or
(&*distr).sample_iter(...)
to reborrow an existing reference.
Example
use rand::thread_rng; use rand::distributions::{Distribution, Alphanumeric, Uniform, Standard}; let rng = thread_rng(); // Vec of 16 x f32: let v: Vec<f32> = Standard.sample_iter(rng).take(16).collect(); // String: let s: String = Alphanumeric.sample_iter(rng).take(7).collect(); // Dice-rolling: let die_range = Uniform::new_inclusive(1, 6); let mut roll_die = die_range.sample_iter(rng); while roll_die.next().unwrap() != 6 { println!("Not a 6; rolling again!"); }
Implementations on Foreign Types
impl<'a, T, D> Distribution<T> for &'a D where
D: Distribution<T>,
[src]
Loading content...D: Distribution<T>,
Implementors
impl Distribution<[f64; 2]> for sprs_rand::rand::distributions::UnitCircle
[src]
impl Distribution<[f64; 3]> for UnitSphereSurface
[src]
impl Distribution<bool> for Bernoulli
[src]
impl Distribution<bool> for Standard
[src]
impl Distribution<char> for Alphanumeric
[src]
impl Distribution<char> for Standard
[src]
impl Distribution<f32> for sprs_rand::rand_distr::Exp1
[src]
impl Distribution<f32> for Open01
[src]
impl Distribution<f32> for OpenClosed01
[src]
impl Distribution<f32> for Standard
[src]
impl Distribution<f32> for sprs_rand::rand_distr::StandardNormal
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Beta
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Cauchy
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::ChiSquared
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Exp1
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Exp
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::FisherF
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Gamma
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::LogNormal
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Normal
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Pareto
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::StandardNormal
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::StudentT
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Triangular
[src]
impl Distribution<f64> for sprs_rand::rand::distributions::Weibull
[src]
impl Distribution<f64> for sprs_rand::rand_distr::Exp1
[src]
impl Distribution<f64> for Open01
[src]
impl Distribution<f64> for OpenClosed01
[src]
impl Distribution<f64> for Standard
[src]
impl Distribution<f64> for sprs_rand::rand_distr::StandardNormal
[src]
impl Distribution<i8> for Standard
[src]
impl Distribution<i16> for Standard
[src]
impl Distribution<i32> for Standard
[src]
impl Distribution<i64> for Standard
[src]
impl Distribution<i128> for Standard
[src]
impl Distribution<isize> for Standard
[src]
impl Distribution<u8> for Standard
[src]
impl Distribution<u16> for Standard
[src]
impl Distribution<u32> for Standard
[src]
impl Distribution<u64> for sprs_rand::rand::distributions::Binomial
[src]
impl Distribution<u64> for sprs_rand::rand::distributions::Poisson
[src]
impl Distribution<u64> for sprs_rand::rand_distr::Binomial
[src]
impl Distribution<u64> for Standard
[src]
impl Distribution<u128> for Standard
[src]
impl Distribution<()> for Standard
[src]
impl Distribution<usize> for Standard
[src]
impl Distribution<Vec<f64, Global>> for sprs_rand::rand::distributions::Dirichlet
[src]
impl Distribution<NonZeroU8> for Standard
[src]
impl Distribution<NonZeroU16> for Standard
[src]
impl Distribution<NonZeroU32> for Standard
[src]
impl Distribution<NonZeroU64> for Standard
[src]
impl Distribution<NonZeroU128> for Standard
[src]
impl Distribution<NonZeroUsize> for Standard
[src]
impl<A> Distribution<(A,)> for Standard where
Standard: Distribution<A>,
[src]
Standard: Distribution<A>,
impl<A, B> Distribution<(A, B)> for Standard where
Standard: Distribution<A>,
Standard: Distribution<B>,
[src]
Standard: Distribution<A>,
Standard: Distribution<B>,
impl<A, B, C> Distribution<(A, B, C)> for Standard where
Standard: Distribution<A>,
Standard: Distribution<B>,
Standard: Distribution<C>,
[src]
Standard: Distribution<A>,
Standard: Distribution<B>,
Standard: Distribution<C>,
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]
Standard: Distribution<A>,
Standard: Distribution<B>,
Standard: Distribution<C>,
Standard: Distribution<D>,
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]
Standard: Distribution<A>,
Standard: Distribution<B>,
Standard: Distribution<C>,
Standard: Distribution<D>,
Standard: Distribution<E>,
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]
Standard: Distribution<A>,
Standard: Distribution<B>,
Standard: Distribution<C>,
Standard: Distribution<D>,
Standard: Distribution<E>,
Standard: Distribution<F>,
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]
Standard: Distribution<A>,
Standard: Distribution<B>,
Standard: Distribution<C>,
Standard: Distribution<D>,
Standard: Distribution<E>,
Standard: Distribution<F>,
Standard: Distribution<G>,
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]
Standard: Distribution<A>,
Standard: Distribution<B>,
Standard: Distribution<C>,
Standard: Distribution<D>,
Standard: Distribution<E>,
Standard: Distribution<F>,
Standard: Distribution<G>,
Standard: Distribution<H>,
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]
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>,
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]
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>,
pub fn sample<R>(&self, _rng: &mut R) -> (A, B, C, D, E, F, G, H, I, J) where
R: Rng + ?Sized,
[src]
R: Rng + ?Sized,
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]
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>,
pub fn sample<R>(&self, _rng: &mut R) -> (A, B, C, D, E, F, G, H, I, J, K) where
R: Rng + ?Sized,
[src]
R: Rng + ?Sized,
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]
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>,
pub fn sample<R>(&self, _rng: &mut R) -> (A, B, C, D, E, F, G, H, I, J, K, L) where
R: Rng + ?Sized,
[src]
R: Rng + ?Sized,
impl<N> Distribution<[N; 2]> for sprs_rand::rand_distr::UnitCircle where
N: Float + SampleUniform,
[src]
N: Float + SampleUniform,
impl<N> Distribution<[N; 2]> for UnitDisc where
N: Float + SampleUniform,
[src]
N: Float + SampleUniform,
impl<N> Distribution<[N; 3]> for UnitBall where
N: Float + SampleUniform,
[src]
N: Float + SampleUniform,
impl<N> Distribution<[N; 3]> for UnitSphere where
N: Float + SampleUniform,
[src]
N: Float + SampleUniform,
impl<N> Distribution<u64> for sprs_rand::rand_distr::Poisson<N> where
N: Float,
Standard: Distribution<N>,
[src]
N: Float,
Standard: Distribution<N>,
impl<N> Distribution<Vec<N, Global>> for sprs_rand::rand_distr::Dirichlet<N> where
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Beta<N> where
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Cauchy<N> where
N: Float,
Standard: Distribution<N>,
[src]
N: Float,
Standard: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::ChiSquared<N> where
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Exp<N> where
N: Float,
Exp1: Distribution<N>,
[src]
N: Float,
Exp1: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::FisherF<N> where
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Gamma<N> where
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::LogNormal<N> where
N: Float,
StandardNormal: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Normal<N> where
N: Float,
StandardNormal: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Pareto<N> where
N: Float,
OpenClosed01: Distribution<N>,
[src]
N: Float,
OpenClosed01: Distribution<N>,
impl<N> Distribution<N> for Pert<N> where
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Poisson<N> where
N: Float,
Standard: Distribution<N>,
[src]
N: Float,
Standard: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::StudentT<N> where
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
[src]
N: Float,
StandardNormal: Distribution<N>,
Exp1: Distribution<N>,
Open01: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Triangular<N> where
N: Float,
Standard: Distribution<N>,
[src]
N: Float,
Standard: Distribution<N>,
impl<N> Distribution<N> for sprs_rand::rand_distr::Weibull<N> where
N: Float,
OpenClosed01: Distribution<N>,
[src]
N: Float,
OpenClosed01: Distribution<N>,
impl<T> Distribution<Option<T>> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 0]> for Standard
[src]
impl<T> Distribution<[T; 1]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 2]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 3]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 4]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 5]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 6]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 7]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 8]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 9]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 10]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 11]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 12]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 13]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 14]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 15]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 16]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 17]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 18]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 19]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 20]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 21]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 22]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 23]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 24]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 25]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 26]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 27]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 28]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 29]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 30]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 31]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<[T; 32]> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<T> Distribution<Wrapping<T>> for Standard where
Standard: Distribution<T>,
[src]
Standard: Distribution<T>,
impl<W> Distribution<usize> for sprs_rand::rand_distr::weighted::alias_method::WeightedIndex<W> where
W: Weight,
[src]
W: Weight,
impl<X> Distribution<usize> for sprs_rand::rand_distr::weighted::WeightedIndex<X> where
X: SampleUniform + PartialOrd<X>,
[src]
X: SampleUniform + PartialOrd<X>,
impl<X> Distribution<X> for Uniform<X> where
X: SampleUniform,
[src]
X: SampleUniform,