Function cs_utils::test::pick_random_rg
source · [−]pub fn pick_random_rg<'a, T, R: SampleRange<usize>>(
collection: &'a [T],
range: R
) -> Vec<&'a T>Expand description
Picks random 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_rg;
let test_vector = vec![1, 2, 3, 4, 5, 6];
let random_items = pick_random_rg(&test_vector, 2..=3);
assert!(
random_items.len() >= 2,
"Must have at least 2 items.",
);
assert!(
random_items.len() <= 3,
"Must have at most 3 items.",
);
for item in random_items {
assert!(
test_vector.contains(item),
);
}
}