Created
July 24, 2014 06:54
-
-
Save goocarlos/5a6fce9e2ff0697e60a4 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* 生成一个 $l 位的 62 进制随机字符串, 其第一位字符不为数字 | |
* @author Luyu Zhang<[email protected]> | |
*/ | |
function mt_rand_base62($l) { | |
$c = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; | |
$letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
for ($s = '', $cl = strlen($c)-1, $i = 0; $i < $l; $s .= $c[mt_rand(0, $cl)], ++$i); | |
$s[0] = is_numeric($s[0])?$letters[mt_rand(0, strlen($letters)-1)]:$s[0]; | |
return $s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment