2 releases
Uses old Rust 2015
0.1.1 | Apr 18, 2018 |
---|---|
0.1.0 | Jun 19, 2015 |
#2057 in Algorithms
538 downloads per month
56KB
1.5K
SLoC
rust-randomkit
Bindings for NumPy's fork of RandomKit.
lib.rs
:
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));
}
}