Skip to main content

sample_distinct

Function sample_distinct 

pub fn sample_distinct(rng: &mut ChaCha8Rng, n: usize, k: usize) -> Vec<usize>
Expand description

Draws k distinct indices from 0..n, uniformly without replacement.

A partial Fisher–Yates shuffle: the first k positions of a 0..n identity are settled by swapping each with a uniformly chosen later position, so the result is an unbiased k-subset in draw order. Returns as many as it can when k > n (all n indices) rather than looping forever — the caller guarantees n ≥ k for a real DE draw, so that path is only a degenerate safety net.