[php]代码库
/**<br> * 生成随机数<br> * <br> * @param int $length 生成的随机数的长度<br> * @param int $numeric 是否生成数字随机数的标志<br> */<br>function random($length, $numeric = 0) {<br> PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);<br> if ($numeric) {<br> $begin = pow(10, $length - 1);<br> $end = pow(10, $length) - 1;<br> $hash = sprintf('%0'.$length.'d', mt_rand($begin, $end));<br> } else {<br> $hash = '';<br> $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';<br> $max = strlen($chars) - 1;<br> for($i = 0; $i < $length; $i++) {<br> $hash .= $chars[mt_rand(0, $max)];<br> }<br> }<br> return $hash;<br>}