php计算抽奖的概率

WBOY
Release: 2016-06-23 13:51:56
Original
749 people have browsed it

<?php //计算抽奖的概率    function get_rand($proArr) {           $result = '';            $proSum = array_sum($proArr);             foreach ($proArr as $key => $proCur) {               $randNum = mt_rand(1, $proSum);               if ($randNum  array('id'=>1,'prize'=>'1000000514','v'=>2),           '1' => array('id'=>2,'prize'=>'1000000513','v'=>5),           '2' => array('id'=>3,'prize'=>'1000000512','v'=>13),           '3' => array('id'=>4,'prize'=>'1000000511','v'=>15),           '4' => array('id'=>5,'prize'=>'1000000510','v'=>25),           '5' => array('id'=>6,'prize'=>'1000000509','v'=>30),  		'6' => array('id'=>7,'prize'=>'1000000508','v'=>10),     );       foreach ($prize_arr as $key => $val) {           $arr[$val['id']] = $val['v'];       }       $rid = get_rand($arr);      $res['yes'] = $prize_arr[$rid-1]['prize'];     unset($prize_arr[$rid-1]);        shuffle($prize_arr);  	$prize_arrcount = count($prize_arr);     for($i=0;$i
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