// 随机生成一组字符串
function build_count_rand($number, $length = 4, $mode = 1) {
if ($mode == 1 && $length < strlen($number)) {
//不足以生成一定数量的不重复数字
return false;
}
$rand = array();
for ($i = 0; $i < $number; $i++) {
$rand[] = rand_string($length, $mode);
}
$unqiue = array_unique($rand);
if (count($unqiue) == count($rand)) {
return $rand;
}
$count = count($rand) - count($unqiue);
for ($i = 0; $i < $count * 3; $i++) {
$rand[] = rand_string($length, $mode);
}
$rand = array_slice(array_unique($rand), 0, $number);
return $rand;
}

时间: 2018-03-11|268次围观|0 条评论
还没有人抢沙发呢~