Skip to content

Instantly share code, notes, and snippets.

@kamath
Created December 6, 2016 04:44
Show Gist options
  • Save kamath/ea6749ed2527be16102b21d609fcf46c to your computer and use it in GitHub Desktop.
Save kamath/ea6749ed2527be16102b21d609fcf46c to your computer and use it in GitHub Desktop.
/*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);
}
}
@kamath
Copy link
Author

kamath commented Nov 14, 2020

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment