Created
March 14, 2019 08:07
-
-
Save Jason-cqtan/d9a656de317d8dae5fa21ff9b95c6b16 to your computer and use it in GitHub Desktop.
生成随机字符串,类似“CuOi3OQNt”
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//方法一 | |
$password_length = 8; | |
function make_seed() { | |
list($usec, $sec) = explode(' ', microtime()); | |
return (float) $sec + ((float) $usec * 100000); | |
} | |
srand(make_seed()); | |
// 随机字符总集 | |
$alfa = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; | |
$token = ""; | |
for($i = 0; $i < $password_length; $i ++) { | |
$token .= $alfa[rand(0, strlen($alfa))]; | |
} | |
echo $token; | |
echo '<br>'; | |
//方法二 | |
// 创建密码 | |
$totalChar = 9; // 密码中字符串的个数 | |
// salt to select chars from | |
$salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789"; | |
srand((double)microtime()*1000000); // 启动随机产生器 | |
$Spass = ""; // 设置初始值 | |
for ($i=0;$i<$totalChar;$i++) // 循环创建密码 | |
$Spass .= substr ($salt, rand() % strlen($salt), 1); | |
echo $Spass; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment