pub fn sample_weighted<R, F, X>(
rng: &mut R,
length: usize,
weight: F,
amount: usize,
) -> Result<IndexVec, WeightError>Expand description
Randomly sample exactly amount distinct indices from 0..length
Results are in arbitrary order (there is no guarantee of shuffling or ordering).
Function weight is called once for each index to provide weights.
This method is used internally by the slice sampling methods, but it can sometimes be useful to have the indices themselves so this is provided as an alternative.
Error cases:
WeightError::InvalidWeightwhen a weight is not-a-number or negative.WeightError::InsufficientNonZerowhen fewer thanamountweights are positive.
This implementation uses O(length + amount) space and O(length) time.