1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
extern crate core;
use rand::{
distributions::{Distribution, Standard},
Rng,
};
use std::cmp::Ordering;
pub struct RandomOrdering(Ordering);
#[allow(clippy::from_over_into)]
impl Into<Ordering> for RandomOrdering {
fn into(self) -> Ordering {
self.0
}
}
impl Distribution<RandomOrdering> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> RandomOrdering {
RandomOrdering(match rng.gen_range(0..2) {
0 => Ordering::Less,
1 => Ordering::Equal,
_ => Ordering::Greater,
})
}
}