Expand description
Nonuniform pseudorandom number generation
This library provides a suite of nonuniform random number generators
via bindings to the Numpy fork of RandomKit. It is approximately
equivalent to Numpy’s numpy.random
module. The API is loosely
based on that of the rand
crate.
This library is not suitable for cryptography.
§Usage
Add this to your Cargo.toml
:
[dependencies]
randomkit = "0.1"
and this to your crate root:
extern crate randomkit;
§Examples
§Standard normal distribution
Sample 1000 numbers from the standard normal distribution (Gauss distribution) with mean 0 and standard deviation 1.
extern crate randomkit;
use randomkit::{Rng, Sample};
use randomkit::dist::Gauss;
fn main() {
let mut rng = Rng::new().unwrap();
for _ in 0..1000 {
println!("{}", Gauss.sample(&mut rng));
}
}
§Normal distribution
Sample 1000 numbers from a normal distribution with mean 10 and standard deviation 5.
extern crate randomkit;
use randomkit::{Rng, Sample};
use randomkit::dist::Normal;
fn main() {
let mut rng = Rng::from_seed(1);
let normal = Normal::new(10.0, 5.0).unwrap();
for _ in 0..1000 {
println!("{}", normal.sample(&mut rng));
}
}
Modules§
- Various distributions that can be sampled from.