hdp_primitives/aggregate_fn/
rand.rs

1use alloy::primitives::U256;
2use rand::{
3    distributions::{Distribution, Standard},
4    Rng,
5};
6
7use super::{integer::Operator, AggregationFunction, FunctionContext};
8
9impl Distribution<AggregationFunction> for Standard {
10    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> AggregationFunction {
11        let index: u8 = rng.gen_range(0..=4);
12        AggregationFunction::from_index(index).unwrap()
13    }
14}
15
16impl Distribution<Operator> for Standard {
17    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Operator {
18        let index: u8 = rng.gen_range(1..=6);
19        Operator::from_index(index).unwrap()
20    }
21}
22
23impl Distribution<FunctionContext> for Standard {
24    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> FunctionContext {
25        FunctionContext {
26            operator: rng.sample(Standard),
27            value_to_compare: U256::from(rng.gen_range(0..=100)),
28        }
29    }
30}