Lottery probability with payout system

169 Views Asked by At

Assume we have a lottery which has following payouts 1,2,5,6,9,10,16. The organizer expects 4% profit from the lottery. I wrote some PHP code which simulates this but I am not good at probability so I am getting wrong results. I wrote my PHP code in this question but I'm sure it will not confuse those people who do not know any programming languages.

for ($i = 0; $i < 10000; $i++)/*number of tickets generated*/ {

    $mainrand   =   rand(1,100); //probable outcome for each ticket

    $pay = 0;

    if($mainrand > 96 && $mainrand <=100){

        $pay = 0;

    }
    if($mainrand > 90 && $mainrand <=96){

        $pay = 16;

    }
    if($mainrand > 81 && $mainrand <=90){

        $pay = 10;

    }
    if($mainrand > 72 && $mainrand <=81){

        $pay = 9;

    }
    if($mainrand > 60 && $mainrand <=72){

        $pay = 6;

    }
    if($mainrand > 48 && $mainrand <=60){

        $pay = 5;

    }
    if($mainrand > 24 && $mainrand <=48){

        $pay = 2;

    }
    if($mainrand > 0 && $mainrand <=24){

        $pay = 1;

    }
    $money += $pay;


}


echo $money;

I expect the $money to be very close to 9600 But it is far away. The logic in this code was to calculate the probability of getting let's say 16X payout from 96 possible outcomes and so on by reducing each probability from outcomes. I increase the random generated number to aprox. 480 and everything gets to its places but I want to understand the logic. Payouts and profit margin can be changed so it would be wonderful if someone could help me understand the logic (algorithm) that this could be counted.

1

There are 1 best solutions below

0
On BEST ANSWER

Here's a table of payout probabilities that has the property that the expected return on a dollar is 96 cents, and which scales like 1/payout. With probability 71% (or so) you win nothing. Not sure if this is close to what you intend, but perhaps it is a start?

1: 0.137142857

2: 0.068571429

5: 0.027428571

6: 0.022857143

9: 0.015238095

10: 0.013714286

16: 0.008571429

The way I built this list: I took the 7 possible payouts and computed their reciprocals ($\frac 1k$ for each payout k). I wanted to use these for my probabilities because the way they decayed felt right to me (I had no scientific reason for preferring this method). Now I just scaled them to fit. That is, I noted that $\sum payout*\frac{1}{payout} = 7$ and I wanted it to be .96 so I multiplied by .96 and divided by 7. To summarize, for each payout k we have $$Prob(k)= \frac 1k \frac {.96}{7}$$ That's it!