生成随机字符串
程序员文章站
2022-05-18 17:56:52
...
##########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;
}
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;
}