29 lines
532 B
PHP
Executable File
29 lines
532 B
PHP
Executable File
<?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;
|
|
}
|
|
|
|
?>
|