生成随机字符串
时间:2021-07-01 10:21:17
帮助过:24人阅读
##########javascript 版###############
function randomChar(l) {
var x="123456789poiuytrewqasdfghjklmnbvcxzQWERTYUIPLKJHGFDSAZXCVBNM";
var tmp="";
for(var i=0;i< l;i++) {
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
}
return tmp;
}
var str = randomChar(20);
document.write(str.toUpperCase());
##########php版###############
function randomChar($len){
if($len<1) return;
$str='';
$ss = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for($i=0;$i<$len;$i++){
$n = rand(0,35);
$str .= $ss[$n];
}
return $str;
}