pub fn random_values_from_slice<T>(
    seed: Seed,
    xs: &[T]
) -> RandomValuesFromSlice<'_, T>
Expand description

Uniformly generates a random reference to a value from a nonempty slice.

The iterator cannot outlive the slice. It may be more convenient for the iterator to own the data, in which case you may use random_values_from_vec instead.

The output length is infinite.

$P(x) = 1/n$, where $n$ is xs.len().

Expected complexity per iteration

Constant time and additional memory.

Panics

Panics if xs is empty.

Examples

use itertools::Itertools;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::slices::random_values_from_slice;

let xs = &[2, 3, 5, 7, 11];
assert_eq!(
    random_values_from_slice(EXAMPLE_SEED, xs)
        .cloned()
        .take(10)
        .collect_vec(),
    &[3, 7, 3, 5, 11, 3, 5, 11, 2, 2]
);
Examples found in repository?
src/orderings/random.rs (line 33)
32
33
34
pub fn random_orderings(seed: Seed) -> RandomOrderings {
    random_values_from_slice(seed, &ORDERINGS).cloned()
}
More examples
Hide additional examples
src/rounding_modes/random.rs (line 32)
31
32
33
pub fn random_rounding_modes(seed: Seed) -> RandomRoundingModes {
    random_values_from_slice(seed, &ROUNDING_MODES).cloned()
}