I'm not sure how you would like to calculate the winner. However, you might just want to design an array, and use a random number and lookup in the array.
You might not want to have anymore probabilities, but if you like so, you can just add as an attribute in the array, then do any math you wish in the if
statement or else
.
$lookup = array(
"0" => array(
"luck" => 9885,
"payout" => 0.00000035,
"probability" => 0.5,
),
"1" => array(
"luck" => 9886,
"payout" => 0.00000351,
"probability" => 0.3,
),
"2" => array(
"luck" => 9993,
"payout" => 0.00003515,
"probability" => 0.1,
),
"3" => array(
"luck" => 9997,
"payout" => 0.00035149,
"probability" => 0.09,
),
"4" => array(
"luck" => 9999,
"payout" => 0.00351494,
"probability" => 0.009,
),
"5" => array(
"luck" => 9999,
"payout" => 0.03514939,
"probability" => 0.001,
),
);
BitocoinPayout(mt_rand(0, 10000), $lookup);
function BitocoinPayout($luck_number, $lookup)
{
foreach ($lookup as $value) {
if ((int) $luck_number < (int) $value["luck"]) {
// or do other math
echo "YAAAY! You just won Stephanie Kostova's jackpot of " . $value["payout"] . " Bitcoin! ";
break;
} else {
continue;
// or do other math
}
}
}
Output
YAAAY! You just won Stephanie Kostova's jackpot of 3.5E-7 Bitcoin!