Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,788 answers

573 users

How to shuffle an array in Rust

1 Answer

0 votes
use rand::seq::SliceRandom;
use rand::thread_rng;

fn main() {
    let mut arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];

    let mut rng = thread_rng();
    arr.shuffle(&mut rng);

    println!("{:?}", arr);
}




/*
run:

[8, 1, 3, 5, 9, 7, 4, 2, 6]

*/

 





answered Jan 4, 2023 by avibootz

Related questions

1 answer 40 views
40 views asked Jan 5, 2023 by avibootz
4 answers 53 views
1 answer 53 views
...