fn simulate(rng: &mut rand::rngs::ThreadRng) -> bool {
  // A: Generate 3 doors, and place a car behind one of them.
  let mut doors: [Door; 3] = [Door::Goat, Door::Goat, Door::Goat];
  let car = rng.gen_range(0, 3);
  doors[car] = Door::Car;

  // B: Assume the contestant always picks door 1 [i=0].
  // No code necessary, we just don't even consider doors[0].

  // C: Host should open either door 2 (if it is a goat) or 3 (otherwise).
  // D: What that really means is the contestant "picks" the other door.
  let switch = match doors[1] {
    // Host reveals "door 2 is a goat", what would you like to do?
    // Contestant switches to door 3 [i=2].
    Door::Goat => &doors[2],

    // Host reveals "door 3 is goat", what would you like to do?
    // Contestant switches to door 2 [i=1].
    Door::Car => &doors[1],
  };

  // E: Deterime/return if the contestant won (got a car) or lost (got a goat).
  match switch {
    Door::Goat => false,
    Door::Car => true,
  }
}
/// Runs a simulation and returns whether the contestant succeeded or not.
Runs a simulation and returns whether the contestant succeeded or not.
Runs a simulation and returns whether the contestant succeeded or not .
fn simulate(rng: &mut rand::rngs::ThreadRng) -> bool {
  // A: Generate 3 doors, and place a car behind one of them.
  let mut doors: [Door; 3] = [Door::Goat, Door::Goat, Door::Goat];
  let car = rng.gen_range(0, 3);
  doors[car] = Door::Car;
  // B: Assume the contestant always picks door 1 [i=0].
  // No code necessary, we just don't even consider doors[0].
  // C: Host should open either door 2 (if it is a goat) or 3 (otherwise).
  // D: What that really means is the contestant "picks" the other door.
  let switch = match doors[1] {
    // Host reveals "door 2 is a goat", what would you like to do?
    // Contestant switches to door 3 [i=2].
    Door::Goat => &doors[2],
    // Host reveals "door 3 is goat", what would you like to do?
    // Contestant switches to door 2 [i=1].
    Door::Car => &doors[1],
  };
  // E: Deterime/return if the contestant won (got a car) or lost (got a goat).
  match switch {
    Door::Goat => false,
    Door::Car => true,
  }
}
fn simulate ( rng : & mut rand :: rngs :: ThreadRng ) -> bool { // A: Generate 3 doors, and place a car behind one of them. let mut doors : [ Door ; 3 ] = [ Door :: Goat , Door :: Goat , Door :: Goat ] ; let car = rng . gen_range ( 0 , 3 ) ; doors [ car ] = Door :: Car ; // B: Assume the contestant always picks door 1 [i=0]. // No code necessary, we just don't even consider doors[0]. // C: Host should open either door 2 (if it is a goat) or 3 (otherwise). // D: What that really means is the contestant "picks" the other door. let switch = match doors [ 1 ] { // Host reveals "door 2 is a goat", what would you like to do? // Contestant switches to door 3 [i=2]. Door :: Goat => & doors [ 2 ] , // Host reveals "door 3 is goat", what would you like to do? // Contestant switches to door 2 [i=1]. Door :: Car => & doors [ 1 ] , } ; // E: Deterime/return if the contestant won (got a car) or lost (got a goat). match switch { Door :: Goat => false , Door :: Car => true , } }
Runs a simulation and returns whether the contestant succeeded or not.
Runs a simulation and returns whether the contestant succeeded or not .
rng
&mut rand::rngs::ThreadRng
rng
&mut rand::rngs::ThreadRng