Answers for "rust generate a random number"

3

random number generator in rust

use rand::Rng;

fn main() {
    let mut rng = rand::thread_rng();

    let n1: u8 = rng.gen();
    println!("Random u8: {}", n1);
    println!("Random u32: {}", rng.gen::<u32>());
    //print with range[1 to 4]
 	let n2: u8 = rand::thread_rng().gen_range(1..5);

}
Posted by: Guest on August-28-2021

Code answers related to "rust generate a random number"

Browse Popular Code Answers by Language