年会抽奖,要求一等奖的中奖概率是0.12%,二等奖中奖概率是3%,三等奖中奖概率是12%,其他中奖概率是都是谢谢惠顾。
1 <?php
2 /**
3 * 抽奖
4 * @param int $total
5 */
6 function getReward($total=1000)
7 {
8 $win1 = floor((0.12*$total)/100);
9 $win2 = floor((3*$total)/100);
10 $win3 = floor((12*$total)/100);
11 $other = $total-$win1-$win2-$win3;
12 $return = array();
13 for ($i=0;$i<$win1;$i++)
14 {
15 $return[] = 1;
16 }
17 for ($j=0;$j<$win2;$j++)
18 {
19 $return[] = 2;
20 }
21 for ($m=0;$m<$win3;$m++)
22 {
23 $return[] = 3;
24 }
25 for ($n=0;$n<$other;$n++)
26 {
27 $return[] = '谢谢惠顾';
28 }
29 shuffle($return);
30 return $return[array_rand($return)];
31 }
32
33 $data = getReward();
34 echo $data;
35 ?>