日期:2014-05-16 浏览次数:20516 次
Array
(
????[1] => 1
????[2] => 5
????[3] => 10
????[4] => 12
????[5] => 22
????[6] => 50
)
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;
}