Sampling from random distributions
Exp1
- A wrapper around an f64
to generate Exp(1) random numbersStandardNormal
- A wrapper around an f64
to generate N(0, 1) random numbers (aof Rand for StandardNormal
of Rand for Exp1
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).
use core::rand::distributions::Exp1;
fn main() {
let exp2 = (*rand::random::<Exp1>()) * 0.5;
println(fmt!("%f is from a Exp(2) distribution", exp2));
}
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).
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))
}
Rand
for StandardNormal
rand
fn rand<R: Rng>(rng: &mut R) -> StandardNormal
Rand
for Exp1
rand
fn rand<R: Rng>(rng: &mut R) -> Exp1