Skip to main content

random_idx_where

Function random_idx_where 

Source
fn random_idx_where<R, T, P>(
    rng: &mut R,
    slice: &mut [T],
    predicate: P,
) -> Option<usize>
where R: Rng, P: Fn(&T) -> bool,
Expand description

Helper: find a random item elt in slice such that predicate(elt) is true. Return the index of that item.

Can arbitrarily reorder slice. This allows us to visit the indices in uniform-at-random order, without having to do any O(N) operations or allocations.