Skip to main content

hermes_tokio_runtime_components/impls/
random.rs

1use cgp::core::Async;
2use hermes_runtime_components::traits::random::RandomGenerator;
3use rand::distributions::uniform::SampleUniform;
4use rand::distributions::Standard;
5use rand::prelude::*;
6
7pub struct ThreadRandomGenerator;
8
9impl<Runtime, T> RandomGenerator<Runtime, T> for ThreadRandomGenerator
10where
11    Runtime: Async,
12    Standard: Distribution<T>,
13    T: Async + SampleUniform + PartialOrd,
14{
15    async fn generate_random(_runtime: &Runtime) -> T {
16        let mut rng = thread_rng();
17        rng.gen()
18    }
19
20    async fn random_range(_runtime: &Runtime, min: T, max: T) -> T {
21        let mut rng = thread_rng();
22        rng.gen_range(min..max)
23    }
24}