Function rand::thread_rng

source ยท
pub fn thread_rng() -> ThreadRng
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));