use crate::Result;
use rand::{RngExt, rng};
use std::collections::HashSet;
pub fn ransac_indices<const N: usize>(
group_count: usize,
index_count: usize,
) -> Result<Vec<[usize; N]>> {
if index_count < N {
return Err("Not enough indices".into());
}
let mut result = Vec::with_capacity(group_count);
let mut working = HashSet::with_capacity(N);
let mut rng = rng();
for _ in 0..group_count {
working.clear();
let mut indices = [0; N];
for i in 0..N {
loop {
let j = rng.random_range(0..index_count);
if !working.contains(&j) {
working.insert(j);
indices[i] = j;
break;
}
}
}
result.push(indices);
}
Ok(result)
}