php产生指定范围长度的随机字符

On 08/26/2010, in php, by kilobug
function random( $min, $max = NULL ) {
	$len = isset($max) ? mt_rand($min, $max) : $min;
	$str = '';
	for($i = 0; $i < $len; ++$i)
		$str .= chr(mt_rand(32, 128));
	return $str;
}

说明:random($min[, $max])
参数:
int $min: 最短长度
int $max[option]: 最大长度

Tagged with:  

One Response to php产生指定范围长度的随机字符

  1. 荒野无灯 says:

    这个好,是我看过的最简洁的一个

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

无觅相关文章插件,快速提升流量