Skip to main content

lawkit_core/generate/
mod.rs

1pub mod benford;
2pub mod normal;
3pub mod pareto;
4pub mod poisson;
5pub mod zipf;
6
7pub use benford::*;
8pub use normal::*;
9pub use pareto::*;
10pub use poisson::*;
11pub use zipf::*;
12
13use crate::error::Result;
14use rand::rngs::StdRng;
15use rand::SeedableRng;
16
17#[derive(Debug, Clone)]
18pub struct GenerateConfig {
19    pub samples: usize,
20    pub seed: Option<u64>,
21    pub output_format: String,
22    pub fraud_rate: f64,
23}
24
25impl GenerateConfig {
26    pub fn new(samples: usize) -> Self {
27        Self {
28            samples,
29            seed: None,
30            output_format: "text".to_string(),
31            fraud_rate: 0.0,
32        }
33    }
34
35    pub fn with_seed(mut self, seed: u64) -> Self {
36        self.seed = Some(seed);
37        self
38    }
39
40    pub fn with_fraud_rate(mut self, rate: f64) -> Self {
41        self.fraud_rate = rate.clamp(0.0, 1.0);
42        self
43    }
44
45    pub fn create_rng(&self) -> StdRng {
46        match self.seed {
47            Some(seed) => StdRng::seed_from_u64(seed),
48            None => StdRng::from_entropy(),
49        }
50    }
51}
52
53pub trait DataGenerator {
54    type Output;
55
56    fn generate(&self, config: &GenerateConfig) -> Result<Self::Output>;
57}