java-高分,帮忙下,谁知道把PhP代码转成Java代码

WBOY
Release: 2016-06-02 11:29:10
Original
1089 people have browsed it

javaphp

$prize_arr = array(
'0' => array('id'=>1,'prize'=>'平板电脑','v'=>3),
'1' => array('id'=>2,'prize'=>'数码相机','v'=>5),
'2' => array('id'=>3,'prize'=>'音箱设备','v'=>10),
'3' => array('id'=>4,'prize'=>'4G优盘','v'=>12),
'4' => array('id'=>5,'prize'=>'Q币10元','v'=>20),
'5' => array('id'=>6,'prize'=>'下次没准就能中哦','v'=>50),
);

foreach ($prize_arr as $key => $val) {
$arr[$val['id']] = $val['v'];
}

$rid = getRand($arr); /*根据概率获取奖项id*/
$res['msg'] = ($rid==6)?0:1;
$res['prize'] = $prize_arr[$rid-1]['prize']; /*中奖项*/
echo json_encode($res);exit;

/*计算概率*/
function getRand($proArr) {
$result = '';

<code>/*概率数组的总概率精度*/$proSum = array_sum($proArr);/*概率数组循环*/foreach ($proArr as $key => $proCur) {    /*相当于每次只能够抽取其中的一个奖项,没抽中就开始抽下一个奖项,直到最后*/    $randNum = mt_rand(1, $proSum);    if ($randNum </code>
Copy after login

}
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!