Sampling from random distributions

Struct Exp1

pub struct Exp1(f64);

A wrapper around an f64 to generate Exp(1) random numbers. Dividing by the desired rate lambda will give Exp(lambda) distributed random numbers.

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

Example

use core::rand::distributions::Exp1;

fn main() {
    let exp2 = (*rand::random::<Exp1>()) * 0.5;
    println(fmt!("%f is from a Exp(2) distribution", exp2));
}

Struct 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 core::rand::distributions::StandardNormal;

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

Implementation of Rand for StandardNormal

Method rand

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

Implementation of Rand for Exp1

Method rand

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