Home >php教程 >php手册 >中奖概率算法

中奖概率算法

WBOY
WBOYOriginal
2016-06-07 11:35:271270browse

根据设定的中奖概率数组进行数据的输出
function getRand($proArr) { //传入的为一维数字数组,此数组中数字即为相应概率<br>         $result = '';<br> <br>         //概率数组的总概率精度<br>         $proSum = array_sum($proArr);<br> <br>         //概率数组循环<br>         foreach ($proArr as $key => $proCur) {<br>             $randNum = mt_rand(1, $proSum);<br>             if ($randNum                  $result = $key;<br>                 break;<br>             } else {<br>                 $proSum -= $proCur;<br>             }<br>         }<br>         unset ($proArr);<br> <br>         return $result;<br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
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