Function rand::seq::sample_iter [] [src]

pub fn sample_iter<T, I, R>(
    rng: &mut R,
    iterable: I,
    amount: usize
) -> Result<Vec<T>, Vec<T>> where
    I: IntoIterator<Item = T>,
    R: Rng

Randomly sample amount elements from a finite iterator.

The following can be returned:

This implementation uses O(len(iterable)) time and O(amount) memory.

Example

use rand::{thread_rng, seq};

let mut rng = thread_rng();
let sample = seq::sample_iter(&mut rng, 1..100, 5).unwrap();
println!("{:?}", sample);