sample
Picks count different elements at random (without replacement), in random order.
Elements are different by position: two equal values in items can both be picked. When
count is at least items.len(), every element is returned, shuffled.
Import
Section titled “Import”Cargo feature random (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
items | &[T] | The elements to pick from. |
count | usize | How many to pick. |
rng | &mut Rng | The generator that decides the picks. |
Returns
Section titled “Returns”Vec<T> — A new Vec of min(count, items.len()) elements.
