/**
* 根据概率获取中奖号码
*/
private function get_rand($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;
}
* 根据概率获取中奖号码
*/
private function get_rand($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;
}
设置中奖概率:
中概率为固定,应修改为自定义每一奖品的概率,即'v'值 ,所有奖的概率加起来为100。
$prize_arr = array(
'0' => array('id'=>1,'prize'=>'一等奖','v'=>1),
'1' => array('id'=>2,'prize'=>'二等奖','v'=>2),
'2' => array('id'=>3,'prize'=>'三等奖','v'=>3),
'3' => array('id'=>4,'prize'=>'四等奖','v'=>5),
'4' => array('id'=>5,'prize'=>'五等奖','v'=>10),
'5' => array('id'=>6,'prize'=>'六等奖','v'=>15),
'6' => array('id'=>7,'prize'=>'谢谢参与','v'=>65)