2 releases

Uses old Rust 2015

0.1.1 Apr 18, 2018
0.1.0 Jun 19, 2015

#1772 in Algorithms

Download history 310/week @ 2023-11-20 274/week @ 2023-11-27 336/week @ 2023-12-04 228/week @ 2023-12-11 80/week @ 2023-12-18 48/week @ 2023-12-25 99/week @ 2024-01-01 164/week @ 2024-01-08 62/week @ 2024-01-15 64/week @ 2024-01-22 55/week @ 2024-01-29 201/week @ 2024-02-05 223/week @ 2024-02-12 136/week @ 2024-02-19 101/week @ 2024-02-26 131/week @ 2024-03-04

592 downloads per month

MIT/BSD-3-Clause

56KB
1.5K SLoC

C 1K SLoC // 0.1% comments Rust 489 SLoC // 0.0% comments

rust-randomkit

Build Status numpy.random for Rust.

Bindings for NumPy's fork of RandomKit.

Documentation


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));
    }
}

Dependencies