/**
* 获取固定长度随机字符串
* @param $n
* @return string
* @throws Exception
*/
function gf_rand_str($n) {
if (!is_int($n)) {
throw new Exception('argument must be int');
}
$alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$str = '';
for ($i=0; $i<$n; $i++) {
$str .= $alpha[rand(0, 35)];
}
return $str;
}

前三位字母后三位数字:

function invite_num($len = 6)
{
$en_chars = [
"A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z"
];
$num_chars = [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
];
$en_shuf = shuffle($en_chars); // 将数组打乱
$num_shuf = shuffle($num_chars);
$output = "";
for ($i = 0; $i < 3; $i++) {
$output .= $en_chars[mt_rand(0, $len)];
}
$output .= substr(getMicroSecondsTimestamp(), 11, 1);
$output .= rand(10, 99);
return $output;
}
function getMicroSecondsTimestamp()
{
$time = microtime();
return substr($time, 11, 10) . str_pad(substr($time, 0, 8) * 1000000,
6, "0", STR_PAD_LEFT);
}
05-06 18:53