Expand description
Produce and consume randomness.
This crate provides utilities to generate random numbers, to convert them to useful types and distributions, and some randomness-related algorithms.
Quick Start
To get you started quickly, the easiest and highest-level way to get a random value is to use urandom::new().next()
.
The Random
struct provides a useful API on all Rngs, while the distributions
module provide further functionality on top of Rngs.
let mut rng = urandom::new();
// Generates a random boolean
if rng.coin_flip() {
// Try printing a random unicode code point (probably a bad idea)!
println!("char: {}", rng.next::<char>());
}
// Generates a float between 13.0 and 42.0
let y: f64 = rng.range(13.0..42.0);
// Shuffles the list of numbers
let mut numbers: Vec<i32> = (1..100).collect();
rng.shuffle(&mut numbers);
This library was inspired by the semi-official rand
crate and an attempt to provide a better experience.
Re-exports
pub use self::rng::Rng;
pub use self::distributions::Distribution;
Modules
Generating random samples from probability distributions.
Random number generators.
Structs
Rich interface for consuming random number generators.