This program simulates a year of euromillions-alike game of luck. Each year it is assumed that it has 121 lotteries and it is assumed that the number of players per lottery is stable and it is 34.000.000 (which is not accurate, because jackpots attract more people, but as an average it is quite representative participation).
Every time that the 5+2 combination is not found, the corresponding amount sums up the next lottery.
The program finishes after the 121 lotteries printing out some statistics for some of the representative winning categories.
It turns out that the 2+0 category is very easy to be achieved, but the 5+2 is too difficult. However, the winners are paid well especially at the high and the low categories.
Since the program requires approximately 18 seconds per lottery, the whole iteration is completed in around 36 minutes.
import java.text.DecimalFormat;
import java.util.Random;
public class Euromillions {
public static void main(String[] args) {
Integer players=34000000;
Integer numberOfLotteries=121;
Integer percentageForWinners=43;
double total_players=0;
Integer number_of_win_5_2=0;
Integer number_of_win_5_1=0;
Integer number_of_win_5_0=0;
Integer number_of_win_4_2=0;
Integer number_of_win_2_0=0;
Integer number_of_jackpots=0;
double amount_of_win_5_2=0;
double amount_of_win_5_1=0;
double amount_of_win_5_0=0;
double amount_of_win_4_2=0;
double amount_of_win_2_0=0;
//the winning tables:
int[] main_table = new int[51];
int[] stars_table = new int[13];
//each person's tables:
int[] main_person_table = new int[51];
int[] stars_person_table = new int[13];
int win=0;
int win_5_2=0;
int win_5_1=0;
int win_5_0=0;
int win_4_2=0;
int win_4_1=0;
int win_3_1=0;
int win_4_0=0;
int win_3_2=0;
int win_3_0=0;
int win_2_2=0;
int win_1_2=0;
int win_2_1=0;
int win_2_0=0;
double win_5_2_per_winner=0;
double win_5_1_per_winner=0;
double win_5_0_per_winner=0;
double win_4_2_per_winner=0;
double win_4_1_per_winner=0;
double win_3_1_per_winner=0;
double win_4_0_per_winner=0;
double win_3_2_per_winner=0;
double win_3_0_per_winner=0;
double win_2_2_per_winner=0;
double win_1_2_per_winner=0;
double win_2_1_per_winner=0;
double win_2_0_per_winner=0;
double win_5_2_dist=50;
double win_5_1_dist=7.216/2;
double win_5_0_dist=1.68/2;
double win_4_2_dist=0.986/2;
double win_4_1_dist=0.934/2;
double win_3_2_dist=1.308/2;
double win_4_0_dist=0.728/2;
double win_2_2_dist=3.407/2;
double win_3_1_dist=3.58/2;
double win_3_0_dist=6.778/2;
double win_1_2_dist=9.618/2;
double win_2_1_dist=28.788/2;
double win_2_0_dist=34.960/2;
//the number below should make 100(%)
double win_dist_others=win_5_1_dist
+win_5_0_dist
+win_4_2_dist
+win_4_1_dist
+win_3_2_dist
+win_4_0_dist
+win_2_2_dist
+win_3_1_dist
+win_3_0_dist
+win_1_2_dist
+win_2_1_dist
+win_2_0_dist;
//System.out.println("win_dist_others: " + win_dist_others);
double money=0;
double profit=0;
double wins=0;
double jackpot=0;
double total_money=0;
double total_profit=0;
double total_wins=0;
DecimalFormat df = new DecimalFormat("###,###,###,###.00");
DecimalFormat df2 = new DecimalFormat("###,###,###,###");
for(int lottery=1; lottery <= numberOfLotteries; lottery++){
System.out.println("lottery: #" + lottery);
//reset the variables:
money = 0;
win_5_2=0;
win_5_1=0;
win_5_0=0;
win_4_2=0;
win_4_1=0;
win_3_1=0;
win_4_0=0;
win_3_2=0;
win_3_0=0;
win_2_2=0;
win_1_2=0;
win_2_1=0;
win_2_0=0;
int main_t=0;
//lottery:
Random lotteryLuck = new Random();
int theLotteryNumber;
for(int i=0;i<50;i++){
main_table[i]=0;
}
for(int i=0;i<12;i++){
stars_table[i]=0;
}
main_t=0;
while(main_t<5){
theLotteryNumber=lotteryLuck.nextInt(50)+1;
if(main_table[theLotteryNumber]==0){
main_table[theLotteryNumber]=1;
System.out.print("[" + theLotteryNumber + "]");
main_t++;
}
}
System.out.print(" - ");
main_t=0;
while(main_t<2){
theLotteryNumber=lotteryLuck.nextInt(12)+1;
if(stars_table[theLotteryNumber]==0){
stars_table[theLotteryNumber]=1;
System.out.print("<" + theLotteryNumber + ">");
main_t++;
}
}
System.out.println("");
for(int people=0;people<players;people++){
win=0;
money = money + 2.5;
Random personLuck = new Random();
int theNumber;
Integer main_person_win;
Integer stars_person_win;
for(int i=0;i<50;i++){
main_person_table[i]=0;
}
for(int i=0;i<12;i++){
stars_person_table[i]=0;
}
main_t=0;
while(main_t<5){
theNumber=personLuck.nextInt(50)+1;
if(main_person_table[theNumber]==0){
main_person_table[theNumber]=1;
main_t++;
}
}
main_t=0;
while(main_t<2){
theNumber=personLuck.nextInt(12)+1;
if(stars_person_table[theNumber]==0){
stars_person_table[theNumber]=1;
main_t++;
}
}
//match the combination
main_person_win = 0;
for(int i=0;i<50;i++){
if(main_person_table[i]==1 && main_table[i]==1){
main_person_win=main_person_win+1;
}
}
stars_person_win = 0;
for(int i=0;i<12;i++){
if(stars_person_table[i]==1 && stars_table[i]==1){
stars_person_win=stars_person_win+1;
}
}
//find the winning category
if(main_person_win==5 && stars_person_win==2 && win==0){
win_5_2++;
win++;
}
if(main_person_win==5 && stars_person_win==1 && win==0){
win_5_1++;
win++;
}
if(main_person_win==5 && stars_person_win==0 && win==0){
win_5_0++;
win++;
}
if(main_person_win==4 && stars_person_win==2 && win==0){
win_4_2++;
win++;
}
if(main_person_win==4 && stars_person_win==1 && win==0){
win_4_1++;
win++;
}
if(main_person_win==3 && stars_person_win==1 && win==0){
win_3_1++;
win++;
}
if(main_person_win==4 && stars_person_win==0 && win==0){
win_4_0++;
win++;
}
if(main_person_win==3 && stars_person_win==2 && win==0){
win_3_2++;
win++;
}
if(main_person_win==1 && stars_person_win==2 && win==0){
win_1_2++;
win++;
}
if(main_person_win==2 && stars_person_win==1 && win==0){
win_2_1++;
win++;
}
if(main_person_win==2 && stars_person_win==2 && win==0){
win_2_2++;
win++;
}
if(main_person_win==3 && stars_person_win==0 && win==0){
win_3_0++;
win++;
}
if(main_person_win==2 && stars_person_win==0 && win==0){
win_2_0++;
win++;
}
}//end loop people
wins = (money * percentageForWinners) /100;
profit = money - wins;
System.out.println("players: " + df2.format(players));
System.out.println("amount collected: " + df.format(money));
System.out.println("amount given to the winners (" + percentageForWinners+ "%): " + df.format(wins));
System.out.println("---------------------");
win_5_2_per_winner = (win_5_2==0?0:(wins*(win_5_2_dist/100)+jackpot)/win_5_2);
win_5_1_per_winner = (win_5_1==0?0:wins*(win_5_1_dist/100)/win_5_1);
win_5_0_per_winner = (win_5_0==0?0:wins*(win_5_0_dist/100)/win_5_0);
win_4_2_per_winner = (win_4_2==0?0:wins*(win_4_2_dist/100)/win_4_2);
win_4_1_per_winner = (win_4_1==0?0:wins*(win_4_1_dist/100)/win_4_1);
win_3_2_per_winner = (win_3_2==0?0:wins*(win_3_2_dist/100)/win_3_2);
win_4_0_per_winner = (win_4_0==0?0:wins*(win_4_0_dist/100)/win_4_0);
win_2_2_per_winner = (win_2_2==0?0:wins*(win_2_2_dist/100)/win_2_2);
win_3_1_per_winner = (win_3_1==0?0:wins*(win_3_1_dist/100)/win_3_1);
win_3_0_per_winner = (win_3_0==0?0:wins*(win_3_0_dist/100)/win_3_0);
win_1_2_per_winner = (win_1_2==0?0:wins*(win_1_2_dist/100)/win_1_2);
win_2_1_per_winner = (win_2_1==0?0:wins*(win_2_1_dist/100)/win_2_1);
win_2_0_per_winner = (win_2_0==0?0:wins*(win_2_0_dist/100)/win_2_0);
System.out.println("win_5_2: " + win_5_2 + " each one: " + df.format(win_5_2_per_winner));
System.out.println("win_5_1: " + win_5_1 + " each one: " + df.format(win_5_1_per_winner));
System.out.println("win_5_0: " + win_5_0 + " each one: " + df.format(win_5_0_per_winner));
System.out.println("win_4_2: " + win_4_2 + " each one: " + df.format(win_4_2_per_winner));
System.out.println("win_4_1: " + win_4_1 + " each one: " + df.format(win_4_1_per_winner));
System.out.println("win_3_2: " + win_3_2 + " each one: " + df.format(win_3_2_per_winner));
System.out.println("win_4_0: " + win_4_0 + " each one: " + df.format(win_4_0_per_winner));
System.out.println("win_2_2: " + win_2_2 + " each one: " + df.format(win_2_2_per_winner));
System.out.println("win_3_1: " + win_3_1 + " each one: " + df.format(win_3_1_per_winner));
System.out.println("win_3_0: " + win_3_0 + " each one: " + df.format(win_3_0_per_winner));
System.out.println("win_1_2: " + win_1_2 + " each one: " + df.format(win_1_2_per_winner));
System.out.println("win_2_1: " + win_2_1 + " each one: " + df.format(win_2_1_per_winner));
System.out.println("win_2_0: " + win_2_0 + " each one: " + df.format(win_2_0_per_winner));
System.out.println("---------------------");
System.out.println("profit: " + df.format(profit));
if(win_5_2==0){
jackpot=jackpot+wins*(win_5_2_dist/100);
number_of_jackpots++;
System.out.println("===================");
System.out.println("jackpot: " + df.format(jackpot));
System.out.println("===================");
}
else{
number_of_win_5_2=number_of_win_5_2+win_5_2;
jackpot=0;
}
number_of_win_5_1=number_of_win_5_1+win_5_1;
number_of_win_5_0=number_of_win_5_0+win_5_0;
number_of_win_4_2=number_of_win_4_2+win_4_2;
number_of_win_2_0=number_of_win_2_0+win_2_0;
amount_of_win_5_2=amount_of_win_5_2+win_5_2_per_winner;
amount_of_win_5_1=amount_of_win_5_1+win_5_1_per_winner;
amount_of_win_5_0=amount_of_win_5_0+win_5_0_per_winner;
amount_of_win_4_2=amount_of_win_4_2+win_4_2_per_winner;
amount_of_win_2_0=amount_of_win_2_0+win_2_0_per_winner;
System.out.println("");
total_money=total_money+money;
total_profit=total_profit+profit;
total_wins=total_wins+wins;
total_players=total_players+players;
}//end loop lottery
System.out.println("");
System.out.println("============");
System.out.println("finally after " + numberOfLotteries + " lotteries:");
System.out.println("------------");
System.out.println("players gambled: " + df2.format(total_players)/*total_players.intValue()*/);
System.out.println("money players gambled: " + df.format(total_money));
System.out.println("profit for the organizers: " + df.format(total_profit));
System.out.println("total money to the winners: " + df.format(total_wins));
System.out.println("jackpots: " + number_of_jackpots);
System.out.println("5+2 wins: " + number_of_win_5_2);
System.out.println("possibility 5+2: 1 out of " + df2.format(total_players/number_of_win_5_2));
System.out.println("possibility 5+1: 1 out of " + df2.format(total_players/number_of_win_5_1));
System.out.println("possibility 5+0: 1 out of " + df2.format(total_players/number_of_win_5_0));
System.out.println("possibility 4+2: 1 out of " + df2.format(total_players/number_of_win_4_2));
System.out.println("...");
System.out.println("possibility 2+0: 1 out of " + df.format(total_players/number_of_win_2_0));
System.out.println("============");
System.out.println("Assuming that 1 year has " + numberOfLotteries + " lotteries");
System.out.println("you need to play " + df.format(total_players/number_of_win_2_0/numberOfLotteries) + " years to win 2+0 (win around " + df.format(amount_of_win_2_0/numberOfLotteries) + " euros) and spend " + df.format(total_players/number_of_win_2_0*2.5) + " euros");
System.out.println("you need to play " + df2.format(total_players/number_of_win_4_2/numberOfLotteries) + " years to win 4+2 (win around " + df.format(amount_of_win_4_2/numberOfLotteries) + " euros) and spend " + df.format(total_players/number_of_win_4_2*2.5) + " euros");
System.out.println("you need to play " + df2.format(total_players/number_of_win_5_0/numberOfLotteries) + " years to win 5+0 (win around " + df.format(amount_of_win_5_0/numberOfLotteries) + " euros) and spend " + df.format(total_players/number_of_win_5_0*2.5) + " euros");
System.out.println("you need to play " + df2.format(total_players/number_of_win_5_1/numberOfLotteries) + " years to win 5+1 (win around " + df.format(amount_of_win_5_1/numberOfLotteries) + " euros) and spend " + df.format(total_players/number_of_win_5_1*2.5) + " euros");
System.out.println("you need to play " + df2.format(total_players/number_of_win_5_2/numberOfLotteries) + " years to win 5+2 (win around " + df.format(amount_of_win_5_2/numberOfLotteries) + " euros) and spend " + df.format(total_players/number_of_win_5_2*2.5) + " euros");
}
}