You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
10 lines
269 B
Rust
10 lines
269 B
Rust
4 years ago
|
use rand::seq::SliceRandom;
|
||
|
|
||
|
/// Chooses a random value from the given iterator
|
||
|
/// panics when the iterator is empty
|
||
|
pub fn choose_unchecked<'a, I: SliceRandom<Item = &'a T>, T>(i: I) -> &'a T {
|
||
|
let mut rng = rand::thread_rng();
|
||
|
|
||
|
i.choose(&mut rng).unwrap()
|
||
|
}
|