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 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)
}
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
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).