js随机密码产生函数
作者:互联网
['abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ','1234567890','~!@#$%^&*()_+";",./?<>']; var rand = function(min, max){
return Math.floor(Math.max(min, Math.random() * (max+1)));
}
var len = rand(8, 16); // 长度为8-16
var pw = '';
for(i=0; i<len; ++i) {
var strpos = rand(0, 3);
pw += text[strpos].charAt(rand(0, text[strpos].length));
} return pw;
}
测试代码: [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
标签:rand,pw,max,js,密码,strpos,随机,var,Math 来源: https://www.cnblogs.com/aivnfjgj/p/12638741.html