Function pick_random

Source
pub fn pick_random<'a, T>(collection: &'a [T], items_count: usize) -> Vec<&'a T>
Expand description

Picks random N items from a vector or slice of items.

§Panics

  • if items_count is larger than total number of items in a collection

§Examples

#[cfg(any(features = "test", test))]
{
    use cs_utils::test::pick_random;
 
    let test_vector = vec![1, 2, 3, 4, 5, 6];
    let random_items = pick_random(&test_vector, 3);
     
    assert_eq!(
        random_items.len(),
        3,
        "Must have 3 items.",
    );
 
    for item in random_items {
        assert!(
            test_vector.contains(item),
        );
    }
}