// MonteCarlo.java // Written (mostly) in class on Tue 6-Oct-09 // Demonstrates coin flips, dice rolling, and Monte Carlo methods // (solving De Mere's problem). import java.util.*; public class MonteCarlo { private static final Random random = new Random(); public static boolean doTrialDeMere1() { for (int roll=0; roll<4; roll++) { if (rollDie(6) == 1) return true; } return false; } public static boolean doTrialDeMere2() { for (int turn=0; turn<24; turn++) { int die1 = rollDie(6); int die2 = rollDie(6); if ((die1 == 1) && (die2 == 1)) return true; } return false; } // odds of a 1 in 4 rolls of a single die public static double deMereOdds1(int trials) { int ok = 0; for (int trial=0; trial