抽奖概率算法

/ 0评 / 0
$reward = array(
0=>array('id'=>0,'area'=>35,'prize'=>'金币5000'),
1=>array('id'=>1,'area'=>30,'prize'=>'蓝钻1天'),
2=>array('id'=>2,'area'=>15,'prize'=>'金币20000'),
3=>array('id'=>3,'area'=>8,'prize'=>'蓝钻3天'),
4=>array('id'=>4,'area'=>6,'prize'=>'金币30000'),
5=>array('id'=>5,'area'=>5,'prize'=>'紫钻2天'),
6=>array('id'=>6,'area'=>1,'prize'=>'获取抽奖机会一次')
);
//area为中奖概率
$r = mt_rand(1, 100); //100为area之和
$b = 0;
foreach (reward ask => $v) {
$b += $v['area'];
if (r <=b) {
$award = $v;
break;
}
}