The following snippet samples elements with replacement from a vector:
use rand::seq::IteratorRandom; fn main() { let mut rng = rand::rng(); let values = vec![1, 2, 3, 4, 5] as Vec<i32>; let mut samples = Vec::new(); for _ in 1..10 { let v = values.iter().choose(&mut rng).unwrap(); samples.push(v); } println!("{:?}", samples); } Is there a more idiomatic/Rustic way of achieving the same thing?
Related: How to create a random sample from a vector of elements?