龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

DZX1.5随机数函数random分享

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
DZX1.5 随机数 br /
DZX1.5 随机数

<?php
/**
 *  @param int $length: 随机数长度
 *  @param int $numeric: 0或非0,其中0表示随机数由全数字组成,非0表示随机数由全字母组成
 *  @return string: 返回生成的随机数
 */
function random($length, $numeric = 0) {
	$seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
	$seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
	$hash = '';
	$max = strlen($seed) - 1;
	for($i = 0; $i < $length; $i++) {
		$hash .= $seed{mt_rand(0, $max)};
	}
	return $hash;
}
echo random('15',1);
echo '<br />';
echo random('15');
/*End of php*/
精彩图集

赞助商链接