Crates.io | srand |
lib.rs | srand |
version | 0.4.0 |
source | src |
created_at | 2019-09-11 09:21:29.689259 |
updated_at | 2019-09-15 07:37:03.422368 |
description | Random number generators and other randomness functionality with simple apis to use. |
homepage | https://github.com/divinerapier/srand |
repository | https://github.com/divinerapier/rand-rs |
max_upload_size | |
id | 164098 |
size | 48,770 |
Random number generators and other randomness functionality inspired by golang standard library with simple apis to use.
let mut r: Rand<_> = Rand::new(RngSource::new(1));
let mut get = vec![];
for _i in 0..50 {
get.push(r.int32n(100));
}
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();
}
srand::ThreadLocal::seed(1234567);
srand::ThreadLocal::int32();
srand::ThreadLocal::uint32();
srand::ThreadLocal::int64();
srand::ThreadLocal::uint64();
let mut buffer = Vec::with_capacity(16);
buffer.resize(16, 0u8);
srand::read(&mut buffer);