Skip to main content

math_audio_optimisation/
distinct_indices.rs

1use rand::Rng;
2use std::collections::HashSet;
3
4pub(crate) fn distinct_indices<R: Rng + ?Sized>(
5    exclude: usize,
6    count: usize,
7    pool_size: usize,
8    rng: &mut R,
9) -> Vec<usize> {
10    debug_assert!(count <= pool_size.saturating_sub(1));
11    let mut selected: HashSet<usize> = HashSet::with_capacity(count);
12    while selected.len() < count {
13        let idx = rng.random_range(0..pool_size);
14        if idx != exclude {
15            selected.insert(idx);
16        }
17    }
18    selected.into_iter().collect()
19}