taken from DB only active deposits will participate anyways this is a simulation we really hope that when round ends there are more ppl
function getLottery($addresses,$jackpot)
//ARRAY WITH ADDRESSES TO RAFFLE AND VARIABLE THAT COINTAINS JACKPOT VALUE
{
shuffle($addresses);//RANDOMIZE INDEX OF ADDRESSES
$lottery_machine = range(1, sizeof($addresses));//SIZEOF PARTICIPATING ADDRESSES
$numbers = array_rand($lottery_machine, 5); //HOW MANY NUMBERS/WINNERS WILL RETURN //;
$log = ""; //WE WILL STORAGE PAYMENTS LOG HERE
$log .= "
Addresses will participate:
";
$numbersCount=1;
foreach ($addresses as $addr) {
$log .= $numbersCount." - ".$addr."
";
$numbersCount++;
}
$log .= "
Starting raffle with $jackpot into jackpot:
";
$earnPercentage=0.50; // SETTING WINNERS AMOUNT | WILL BE DIVIDED FOR 50%
$numbersCount=1;
foreach ($numbers as $winner) {
if (sizeof($numbers) == $numbersCount){ //CHECKS TO DETERMINE IF IS THE LAST PAYMENT TO SEND REST OF JACKPOT
$winnerAmount = $jackpot; // IF IS THE LAST WILL SEND REST OF POT
}
else{
$winnerAmount = $jackpot * $earnPercentage;
//IF IS NOT LAST WILL DIVIDE JACKPOT FROM AMOUT | 50% LESS PER WINNER
}
try {
//$response = $api->pay($winner,$winnerAmount); //MAKING PAYMENT
$log .= "Address:".$addresses[$winner]." won
$numbersCount place has earned
$winnerAmount";//LOGGING TO RETURN
} catch(Exception $e)
{
$log .= $e."\n";
}
$jackpot = $jackpot - $winnerAmount;//RESTING PAID AMOUNT FROM JACKPOT
//$earnPercentage = $earnPercentage * 0.50;//DIVIDING THE WINNER AMOUNT 50% LESS FOR NEXT PAYMENT
$numbersCount++;
}
return $log."
";
}