Crate rand
Utilities for random number generation
Rand provides utilities to generate random numbers, to convert them to useful types and distributions, and some randomness-related algorithms.
Quick Start
// The prelude import enables methods we use below, specifically
// Rng::random, Rng::sample, SliceRandom::shuffle and IndexedRandom::choose.
use *;
// Get an RNG:
let mut rng = rng;
// Try printing a random unicode code point (probably a bad idea)!
println!;
// Try printing a random alphanumeric value instead!
println!;
// Generate and shuffle a sequence:
let mut nums: = .collect;
nums.shuffle;
// And take a random pick (yes, we didn't need to shuffle first!):
let _ = nums.choose;
The Book
For the user guide and further documentation, please read The Rust Rand Book.
Modules
Functions
-
fill
Fill any type implementing
Fillwith random data - random Generate a random value using the thread-local random number generator.
-
random_bool
Return a bool with a probability
pof being true. -
random_iter
Return an iterator over [
random()] variates - random_range Generate a random value in the given range using the thread-local random number generator.
-
random_ratio
Return a bool with a probability of
numerator/denominatorof being true. - thread_rng Access the thread-local generator