Skip to main content

teaql_tool_extra/
random.rs

1use rand::RngExt;
2
3pub struct RandomTool;
4
5impl RandomTool {
6    pub fn new() -> Self {
7        Self
8    }
9
10    pub fn int(&self, min: i64, max: i64) -> i64 {
11        let mut rng = rand::rng();
12        rng.random_range(min..=max)
13    }
14
15    pub fn float(&self, min: f64, max: f64) -> f64 {
16        let mut rng = rand::rng();
17        rng.random_range(min..=max)
18    }
19
20    pub fn boolean(&self) -> bool {
21        let mut rng = rand::rng();
22        rng.random_bool(0.5)
23    }
24}
25
26impl Default for RandomTool {
27    fn default() -> Self {
28        Self::new()
29    }
30}