pub use crate::rng::{ProvablyFairConfig, ProvablyFairRNG};
use std::fmt;
#[derive(Debug)]
pub struct SimulationResult {
pub pocket: u8,
}
impl fmt::Display for SimulationResult {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.pocket)
}
}
pub fn simulate(config: ProvablyFairConfig) -> SimulationResult {
let mut rng: ProvablyFairRNG<f64> = ProvablyFairRNG::from_config(config);
let pocket = (rng.next().unwrap() * 37.) as u8;
SimulationResult { pocket }
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn simulate_roulette() {
let config = ProvablyFairConfig::new("client seed", "server seed", 1);
let result = simulate(config);
assert_eq!(result.pocket, 27);
let config = ProvablyFairConfig::new("client seed", "server seed", 2);
let result = simulate(config);
assert_eq!(result.pocket, 19);
}
}