struct Normal<F> { ... }
Normal (Gaussian) distribution over the real numbers.
This distribution is parameterized by a mean and a standard deviation. The mean is the center of the distribution, and the standard deviation controls the spread.
Example
use std::random::{thread_rng, Normal};
let dist: Normal<f64> = Normal::new(2.0, 3.0);
// Prints a random number from a normal distribution with mean 2 and
// standard deviation 3
println!("{}", dist.sample(thread_rng()));
Run this example
Methods
impl Normal<F> { ... }
-
fn new(mean: F, std_dev: F) -> Normal<F>
Create a normal distribution with a given mean and standard deviation.
-
fn standard() -> Normal<F>
Create a standard normal distribution
Standard normal distribution has a mean of 0 and standard deviation of 1.
-
Samples a distribution using a provided random number generator.
Mixins
impl Normal<F> { ... }
-
mixin<R> Distribution<Normal<F>, F, 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