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