Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

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);

}
 
PREVIOUS NEXT
Tagged: #random #number #generator #rust
ADD COMMENT
Topic
Name
8+2 =