我写了一个简单的JS脚本来生成随机密码。
function Password(l) {
this.l = l;
}
Password.prototype.generate = function () {
var p = "";
for (let i=0; i < this.l; i++) {
p = p + String.fromCharCode(Math.floor(Math.random() * (122 - 97 + 1) + 97));
}
return p;
};
p = new Password(8);
console.log(p.generate());
查找字符代码
console.log("A".charCodeAt(0));
console.log("Z".charCodeAt(0));
console.log("0".charCodeAt(0));
console.log("9".charCodeAt(0));
我的一个想法是完成这项工作,但我不知道怎么做?
if (Math.random() < .5) {
console.log("OK");
} else {
console.log("NOT OK");
}
console.log(Math.random());
先谢谢此事 如果有一些编写代码,那么理解
会更好更新1:有人用新功能完成代码意味着大写字母,并通过随机播放为其添加数字。