Random numbers in range

    0

    0

    Giovanny Gongora

    Codiga's Rust Recipes

    Get a number in a defined range

    use rand::distributions::{Distribution, Uniform};
    
    fn main() {
      let mut rng = rand::thread_rng();
      let die = Uniform::from(1..7);
      loop {
        let throw = die.sample(&mut rng);
        println!("Roll the die: {}", throw);
        if throw == 6 {
          break;
        }
      }
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.