复制代码 代码如下:
void mt_srand ( int seed )
复制代码 代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)><?php
// seed with microseconds
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
mt_srand(make_seed());
$randval = mt_rand();
?>
复制代码 代码如下:
mt_rand(min,max)
复制代码 代码如下:
<?phpecho(mt_rand());
echo(mt_rand());
echo(mt_rand(10,100));
?>
复制代码 代码如下:
<?php
/*
* $length:随机数字符串的长度
* $type:产生随机数的类型
* */
function random($length, $type = "") {
$chars = !$type ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz" : "0123456789abcdef";
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$string .= $chars[mt_rand(0, $max)];
}
return $string;
}
$var=random(32,'haha');
echo($var);
?>
新闻热点
疑难解答