Follow the steps to implement this recipe:
- Open the main.rs file in the src directory in your preferred text editor.
- Write the code header with the relevant information:
//-- #########################
//-- Task: To generate a random number between the range of 0 to 10
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 04 May 17
//-- #########################
- Copy paste the following code snippet to the main.rs file after the code header:
extern crate rand;
use rand::Rng;
fn main() {
let mut rng = rand::thread_rng();
println!("{}", rng.gen_range(0, 10));
}
- Save the file and run the project by following the next command:
cargo run
We should get the following output on execution of the code: