标签:log ros get randn plist for 精度 set 抽奖
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; }
$rid = $this->get_rand($arr); //根据概率获取奖项id
foreach($plist as $key => $val){ if($val[‘prize_id‘] == $rid){ $res[‘yes‘] = $val[‘prize_name‘]; //中奖项 } }
标签:log ros get randn plist for 精度 set 抽奖
原文地址:http://www.cnblogs.com/finnlee/p/6146129.html