Advertisement
cwchen

[Rust] Modifying array elements with a mutable iterator.

Aug 22nd, 2017
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.21 KB | None | 0 0
  1. extern crate rand;
  2.  
  3. use rand::Rng;
  4.  
  5. fn main() {
  6.     const SIZE: usize = 100;
  7.     let mut array = [0; SIZE];
  8.  
  9.     for e in array.iter_mut() {
  10.         *e = rand::thread_rng().gen_range(1, 100 + 1);
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement