flip coin

This commit is contained in:
Henri Bourcereau 2024-01-27 19:11:23 +01:00
parent ad3635e275
commit 6f504acf12
4 changed files with 19 additions and 17 deletions

View file

@ -24,6 +24,14 @@ impl Dices {
}
}
/// Heads or tails
pub fn coin(self) -> bool {
let between = Uniform::new_inclusive(1, 2);
let mut rng = rand::thread_rng();
between.sample(&mut rng) == 1
}
pub fn to_bits_string(self) -> String {
format!("{:0>3b}{:0>3b}", self.values.0, self.values.1)
}