Struct std::random::UniformInteger
Uniform distribution over a range of integers.
Each integer in the range will be equally likely to be sampled regardless of the range kind.
Example
use std::random::{thread_rng, UniformInteger};
let dist = UniformInteger::new(0..=5);
println!("{}", dist.sample(thread_rng()));
// Equivalent to
// println!("{}", thread_rng().next(0..=5));
Run this example
Methods
-
fn new(range: Range) -> UniformInteger<T, Range>
Creates a new uniform distribution from an integer range
Example
use std::random::{thread_rng, UniformInteger}; let dist = UniformInteger::new(0..=5); println!("{}", dist.sample(thread_rng()));
Run this example -
fn sample<R>(self: &UniformInteger<T, Range>, rng: &mut R) -> T
R: Rng<R>Samples a distribution using a provided random number generator.
Mixins
-
mixin<R> Distribution<UniformInteger<T, Range>, T, R>
R: Rng<R> -
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