ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ /** * \[build_count_rand 生成一定数量的随机数,并且不重复\] * @param \[type\] $number \[数量\] * @param integer $length \[长度\] * @param integer $mode \[字串类型 0 字母 1 数字 其它 混合\] * @return \[type\] \[description\] */ 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; } ~~~