79468970

Date: 2025-02-26 08:22:13
Score: 0.5
Natty:
Report link

My own answer which produces the same effect is:

use rand::seq::IteratorRandom;

fn main() {
    let mut rng = rand::rng();
    let values = vec![1, 2, 3, 4, 5] as Vec<i32>;
    let samples: Vec<_> = (1..10).map(|_| *values.iter().choose(&mut rng).unwrap()).collect();
    println!("{:?}", samples);
}

Remark: I am not however sure how to fix the seed to have exactly reproducible results.

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Roger V.