[php]
<?php
function mac_rand( $length ) // 取得随机字符或数字
{
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand( (double)microtime() * 1000000 );
for( $i = 0; $i < $length; $i++ )
{
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
function mac_rand_mun( $length ) // 数字
{
$hash = '';
$chars = '0123456789';
$max = strlen($chars) - 1;
mt_srand( (double)microtime() * 1000000 );
for( $i = 0; $i < $length; $i++ )
{
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
function mac_rand_char( $length ) // 英文字母
{
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand( (double)microtime() * 1000000 );
for( $i = 0; $i < $length; $i++ )
{
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
?>
[/php]
|