Just thought I would show you guys a nifty little program I made in Java to simulate your odds on the dice game Craps. The main for loop of the program simulates one game, and you can adjust int i to simulate different numbers of games. The final output shows your total wins, the total house wins and your winning percentage. As you can see, the house ALWAYS wins!
package myPackage;
import java.util.Random;
class Main{
public static void main(String args[])
{
float houseWins = 0;
float yourWins = 0;
int thisSum;
Random myRandom = new Random();
for(int i = 0; i <= 10000; i++)
{
/**
Roll two die, take their sums to establish the "come out roll"
**/
int roll1 = myRandom.nextInt(6) + 1;
int roll2 = myRandom.nextInt(6) + 1;
int comeOutRoll = roll1 + roll2;
//Automatic win
if(comeOutRoll == 7 || comeOutRoll == 11)
{
yourWins += 1;
}
//Automatic loss
else if (comeOutRoll == 2 || comeOutRoll == 3 || comeOutRoll == 12){
houseWins += 1;
}
//Play the game
else
{
boolean playing = true;
while(playing)
{
roll1 = myRandom.nextInt(6) + 1;
roll2 = myRandom.nextInt(6) + 1;
thisSum = roll1 + roll2;
if(thisSum == comeOutRoll)
{
yourWins += 1;
playing = false;
}
else if (thisSum == 7){
houseWins += 1;
playing = false;
}
}
}
}
float winPercentage = (yourWins)/(yourWins + houseWins);
//Print the results
System.out.println("Your wins: " + yourWins);
System.out.println("House wins: " + houseWins);
System.out.println("You win: " + winPercentage + "% of the time!");
}
}