srand

Crates.iosrand
lib.rssrand
version0.4.0
sourcesrc
created_at2019-09-11 09:21:29.689259
updated_at2019-09-15 07:37:03.422368
descriptionRandom number generators and other randomness functionality with simple apis to use.
homepagehttps://github.com/divinerapier/srand
repositoryhttps://github.com/divinerapier/rand-rs
max_upload_size
id164098
size48,770
divinerapier (divinerapier)

documentation

https://docs.rs/srand

README

Srand

Random number generators and other randomness functionality inspired by golang standard library with simple apis to use.

A simple rng random generator

let mut r: Rand<_> = Rand::new(RngSource::new(1));
let mut get = vec![];
for _i in 0..50 {
    get.push(r.int32n(100));
}

A threads safe random generator

let r: Rand<_> = Rand::new(LockedSource::new(1));
let mut handles = vec![];
for i in 0..4 {
    let mut r = r.clone();
    let h = std::thread::spawn(move || {
        for j in 0..3 {
            println!("thread: {}, index: {}, {}", i, j, r.i64());
        }
    });
    handles.push(h);
}
for h in handles {
    h.join().unwrap();
}

Thread local apis

srand::ThreadLocal::seed(1234567);
srand::ThreadLocal::int32();
srand::ThreadLocal::uint32();
srand::ThreadLocal::int64();
srand::ThreadLocal::uint64();

Random data

let mut buffer = Vec::with_capacity(16);
buffer.resize(16, 0u8);
srand::read(&mut buffer);
Commit count: 18

cargo fmt