Created
December 6, 2016 04:44
-
-
Save kamath/ea6749ed2527be16102b21d609fcf46c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Donny Mace's requirements: | |
In the 17th century, the discipline of probability theory got its start when a gambler asked a mathematician friend to explain some observations about dice games. Why did he, on average, lose a bet that at least one six would appear when rolling a die four times? And why did he seem to win a similar bet, getting at least one double-six when rolling a pair of dice 24 times? | |
Nowadays, it seems astounding that any person would roll a pair of dice 24 times in a row, and then repeat that many times over. Let’s do that experiment on a computer instead. Write a program OldWorldGambling that will simulate each game a million times and print out the wins and losses, assuming each bet was for $1. Use the Dice class that we created earlier in class. | |
*/ | |
import java.util.Random; | |
public class OldWorldGambling { | |
public static void main(String[] args) { | |
int wins = 0; | |
int losses = 0; | |
Random r = new Random(); | |
for(int a = 0; a<1000000; a++) {if(r.nextInt(6) + 1 == 6) wins++; else losses++;} | |
System.out.println("Wins in game 1: "+ wins+", Losses in game 1: "+ losses); | |
//Game 1 works fine. Game 2 is a total ass fucker. It keeps giving me 1000000 losses | |
wins = 0; | |
losses = 0; | |
for(int a = 0; a<1000000; a++) { | |
int numsix = 0; | |
for(int b = 0; b<24; b++) { | |
if(r.nextInt() == 6) {numsix++;System.out.println(numsix);} | |
if(numsix > 1) { | |
wins++; | |
break; | |
} | |
} | |
if(numsix < 2) losses++; | |
} | |
System.out.println("Wins in game 2: "+ wins+", Losses in game 2: "+ losses); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks