bnbweb/includes/lib_lottery.php

29 lines
504 B
PHP
Raw Permalink Normal View History

2022-11-14 17:31:15 +00:00
<?php
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
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;
}
2022-11-14 15:49:28 +00:00
?>