滑稽 的博客

php生成400个不重复的16位随机数

需求是:php生成400个不重复的16位随机数,装进数组


function str_rand()

{

    $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    $str = "___".substr(str_shuffle($str),0,16);

    return $str;

}

$arr = [];

while(count($arr) < 400) 

{

    $tmp = str_rand();

    $arr[$tmp] = $tmp;

}


var_dump(array_keys($arr));


标签: php随机数
评论
< >
更多文章来:https://alpha2016.github.io
< >
© 滑稽 的博客 | Powered by LOFTER