How to do it...

Follow the steps to implement this recipe:

  1. Open the main.rs file in the src directory in your preferred text editor.
  2. 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
//-- #########################
  1. 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));
}
  1. 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:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.111.197