php生成随机函数示例
<?php
$a=sp_random_score();
echo $a;
// 生成随机评分,在数组中随机产生一个值
function sp_random_score($len = 1) {
$chars = array(
"3.5", "3.6", "3.7","3.8","3.9","4.0","4.1", "4.2", "4.3", "4.4","4.5", "4.6","4.7", "4.8","4.9", "5.0"
);
$charsLen = count($chars) - 1;
shuffle($chars);// 将数组打乱
$output = "";
for ($i = 0; $i < $len; $i++) {
$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
?>