Skip to content
Snippets Groups Projects

fix random item draw

Merged STEVAN Antoine requested to merge fix-shuffle into main
1 file
+ 3
1
Compare changes
  • Side-by-side
  • Inline
use rand::{Rng, RngCore};
use std::collections::HashSet;
fn draw_unique_indices(n: usize, vec_len: usize, rng: &mut impl RngCore) -> HashSet<usize> {
fn draw_unique_indices(n: usize, vec_len: usize, rng: &mut impl RngCore) -> Vec<usize> {
let mut indices = HashSet::new();
while indices.len() < n {
@@ -9,6 +9,8 @@ fn draw_unique_indices(n: usize, vec_len: usize, rng: &mut impl RngCore) -> Hash
indices.insert(idx);
}
let mut indices: Vec<usize> = indices.into_iter().collect();
indices.sort();
indices
}
Loading