Expand description
§Tiny RNG, a minimal random number generator
Warning: Not cryptographically secure.
Proven mathematical methods are applied to obtain unbiased samples. Specifically, rejection sampling is applied to obtain samples from the uniform distribution on an integer range and Fisher–Yates shuffle is applied to obtain a random permutation from the uniform distribution on the set of all permutations.
use tiny_rng::{Rng, Rand};
let mut rng = Rng::from_seed(0);
// Throw a dice:
println!("{}", rng.rand_range_u32(1, 7));
// Choose a random color:
let colors = ["red", "green", "blue"];
println!("{}", rng.choice(&colors));
// Shuffle an array:
let mut a = [1, 2, 3, 4];
rng.shuffle(&mut a);
println!("{:?}", a);
Structs§
- Rng
- Recommended engine. Currently Xorshift128+.
Traits§
- Rand
- Provided utilities.
Functions§
- rand_
iter - A helper function to turn random number generation into an iterator.