Advertisement
cwchen

[Rust] Modifying array elements with indexs.

Aug 22nd, 2017
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.31 KB | None | 0 0
  1. // Call rand package for random number generation
  2. extern crate rand;
  3.  
  4. use rand::Rng;
  5.  
  6. fn main() {
  7.     const SIZE: usize = 10;
  8.     let mut array = [0; SIZE];
  9.  
  10.     for i in 0..array.len() {
  11.         // Set a random number between 1 and 100
  12.         array[i] = rand::thread_rng().gen_range(1, 100 + 1);
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement