php 批量生成随机字符串,[转载]PHP批量生成随机字符串程序

$db_host = 'localhost';

$db_user = 'root';

$db_pwd = '123456';

$db_name = 'test';

$link = mysql_pconnect($db_host, $db_user, $db_pwd) or

die('连接失败');

mysql_select_db($db_name, $link);

function random($length,$string =

'0123456789abcdefghijklmnopqrstuvwxyz') {

$rstr = '';

$strlen = strlen($string);

for ($i=0; $i

$rstr .=

$string{mt_rand(0,$strlen-1)};

}

return $rstr;

}

function getmtime() {

$time = explode(' ', microtime());

return $time[0]+$time[1];

}

if ( $_GET['ac'] == 'make' ) {

$stime = intval($_GET['stime']);

$total = intval($_GET['total']);

$num = intval($_GET['num']);

$limit = intval($_GET['limit']);

$starttime = getmtime();

if ( empty($stime) ) {

$stime = $starttime;

}

!$total && $total =

intval($_POST['total']);

!$num && $num =

intval($_POST['num']);

!$limit && $limit =

intval($_POST['limit']);

$sql = "INSERT INTO pub_code (code) VALUES ";

$sp = '';

for ( $i = 1; $i <= $num; $i++ ) {

$sql .=

$sp.'(''.random(9).'')';

$sp = ', ';

}

mysql_unbuffered_query($sql, $link);

$count = mysql_result(mysql_query("SELECT COUNT(*) FROM

pub_code"), 0);

if ( $count >= $total ) {

$endtime = getmtime();

exit('任务完成,共生成'.$count.'个,耗时:'.number_format($endtime

- $stime, 6).'秒');

} else {

$endtime = getmtime();

$url =

"random.php?ac=make&stime={$stime}&total={$total}&num={$num}&limit={$limit}";

$percent = ceil($count/$total

* 100);

$barlen = $percent * 6;

$ctime =

number_format($endtime - $starttime, 3);

$ovtime =

ceil((($total-$count)/$num)*$ctime + (($total-$count)/$num) *

($limit/1000));

echo

'

共生成'.$total.'个,已完成'.$count.'个,本次耗时

'.$ctime.' 秒,预计剩余时间

'.floor($ovtime/3600).'小时'.floor(($ovtime600)/60).''.($ovtime`).'

style="height:23px;line-height:23px;width:600px;border:1px solid

#FAA547;font-family:Verdana;color:#fff">

style="background:#FAA547;width:'.$barlen.'px">'.$percent.'%

';

}

} else {

?>

随机数生成器

cellpadding="5" cellspacing="1"

bgcolor="#CCCCCC">

bgcolor="#f0f0f0">随机数生成器

action="random.php?ac=make" target="make">

每次生成

size="10" /> 个,共生成

name="total" value="100000" size="10" /> 个,时间间隔

size="10" /> 毫秒,

value=" 开 始 " style="padding:3px" />

frameborder="0">

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值