php can set the probability of winning lottery program code sharing

  • 2020-12-19 20:55:57
  • OfStack


<?php
/**
 *  Lucky draw 
 * @param int $total
 */
function getReward($total=1000)
{
 $win1 = floor((0.12*$total)/100);
 $win2 = floor((3*$total)/100);
 $win3 = floor((12*$total)/100);
 $other = $total-$win1-$win2-$win3;
 $return = array();
 for ($i=0;$i<$win1;$i++)
 {
 $return[] = 1;
 }
 for ($j=0;$j<$win2;$j++)
 {
 $return[] = 2;
 }
 for ($m=0;$m<$win3;$m++)
 {
 $return[] = 3;
 }
 for ($n=0;$n<$other;$n++)
 {
 $return[] = ' Thank you for your help ';
 }
 shuffle($return);
 return $return[array_rand($return)];
}

$data = getReward();
echo $data;
?> 

This article mainly introduces a lottery procedure, which requires that the probability of winning the first prize is 0.12%, the probability of winning the second prize is 3%, the probability of winning the third prize is 12%, and the other probability of winning is all thanks for your help


Related articles: