生成四位随机数的PHP代码(转)
- 纯数字的四位随机数
- rand(1000,9999)
- 数字和字符混搭的四位随机字符串:
1 function GetRandStr($len) 2 { 3 $chars = array( 4 "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", 5 "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", 6 "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", 7 "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", 8 "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", 9 "3", "4", "5", "6", "7", "8", "9" 10 ); 11 $charsLen = count($chars) - 1; 12 shuffle($chars); 13 $output = ""; 14 for ($i=0; $i<$len; $i++) 15 { 16 $output .= $chars[mt_rand(0, $charsLen)]; 17 } 18 return $output; 19 } 20 echo GetRandStr(4);
转自http://blog.csdn.net/happy_jijiawei/article/details/50581094

浙公网安备 33010602011771号