Function rand::thread_rng
source · pub fn thread_rng() -> ThreadRng
Available on crate features
std
and std_rng
only.Expand description
Access the thread-local generator
Returns a reference to the local ThreadRng
, initializing the generator
on the first call on each thread.
Example usage:
use rand::Rng;
// rand::random() may be used instead of rand::thread_rng().gen():
println!("A random boolean: {}", rand::random::<bool>());
let mut rng = rand::thread_rng();
println!("A simulated die roll: {}", rng.gen_range(1..=6));