Struct std::rand::distributions::StandardNormal

pub struct StandardNormal(f64);

A wrapper around an f64 to generate N(0, 1) random numbers (a.k.a. a standard normal, or Gaussian). Multiplying the generated values by the desired standard deviation sigma then adding the desired mean mu will give N(mu, sigma^2) distributed random numbers.

Note that this has to be unwrapped before use as an f64 (using either * or cast::transmute is safe).

Example

use std::rand::distributions::StandardNormal;

fn main() {
    let normal = 2.0 + (*rand::random::<StandardNormal>()) * 3.0;
    printfln!("%f is from a N(2, 9) distribution", normal)
}

Trait Implementations

impl Rand for StandardNormal

fn rand<R: Rng>(rng: &mut R) -> StandardNormal

Generates a random instance of this type using the specified source of randomness