Reputation: 858
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.
for ($i = 0; $i < 10000; $i++) {
$mainrand = rand(1,100);
$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. 450 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.
Upvotes: 0
Views: 407
Reputation: 3972
You can calculate the expected value of playing the lottery by adding up the probability of a payout times its value for all possible payouts. When I do this, I get an expected value of 4.71. Notice that you have a 96% chance of winning at least 1 (and in many cases, much more than 1), so you will definitely not be getting a 4% profit. You need to make the expected value = .96, rather than a probability of winning = .96.
Upvotes: 2