Protocol std::random::Distribution
protocol Distribution<Self, T, R> { ... }
R: Rng<R>
Probability distributions
Objects implementing Distribution can be used to sample random values using an arbitrary random number generator implementing Rng.
Distributions should be cheap to clone and should not store any state. The state should be stored in the random number generator.
Required methods
-
fn sample(self: &Self, rng: &mut R) -> T
Samples a distribution using a provided random number generator.
Provided methods
-
fn sample_iter(self: &Self, rng: &mut R) -> DistIterator<Self, T, R>
Raturns an iterator producing an infinite stream of values sampled from the distribution.
Example
use std::random::{thread_rng, UniformInteger}; let dist = UniformInteger::new(0..=5); // Prints 10 random numbers between 0 and 5 inclusive for i in dist.sample_iter(thread_rng()).take(10) { println!("{}", i); }
Run this example