定义中奖概率数组
1 2 3 4 5 6 7 8
| private $innerRate = array( '1' => 1, '2' => 200, '3' => 500, '4' => 100000, '5' => 300000, '6' => 1693000, );
|
调用函数
1.$i = $this->getRand($this->innerRate)
;
2.根据返回的$i,处理当前返回逻辑,if和switch都可以。
1 2 3 4 5 6
| if($i==1) { echo "一等奖"; }else{ echo "二等奖"; }
|
基础函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| private function getRand($proArr) { $result = ''; $proSum = array_sum($proArr); foreach ($proArr as $key => $proCur) { $randNum = mt_rand(1, $proSum); if ($randNum <= $proCur) { $result = $key; break; } else { $proSum -= $proCur; } } unset($proArr); return $result; }
|