CnSwift - 雨燕

agile development - 敏捷开发

php概率函数

概率

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//概率
function getRand($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;
}
更多精彩内容,请关注公众号 Golang语言开发栈公众号二维码
感谢赞赏.

Welcome to my other publishing channels