[][src]Function rand::seq::sample_slice_ref

pub fn sample_slice_ref<'a, R, T>(
    rng: &mut R,
    slice: &'a [T],
    amount: usize
) -> Vec<&'a T> where
    R: Rng

Randomly sample exactly amount references from slice.

The references are non-repeating and in random order.

This implementation uses O(amount) time and memory.

Panics if amount > slice.len()

Example

use rand::{thread_rng, seq};

let mut rng = thread_rng();
let values = vec![5, 6, 1, 3, 4, 6, 7];
println!("{:?}", seq::sample_slice_ref(&mut rng, &values, 3));