生成随机数8位大小写随机数
//生成随机密码
password() {
function getNumber() { return Math.floor(Math.random() * 10) }; // 0~9的数字
function getUpLetter() { return String.fromCharCode(Math.floor(Math.random() * 26) + 65) }; // A-Z
function getLowLetter() { return String.fromCharCode(Math.floor(Math.random() * 26) + 97) }; // a-z
function confirmItem() { return [getNumber(), getUpLetter(), getLowLetter()] }
// 随机index
const getIndex = () => Math.floor(Math.random() * 3);
// 从0-9,a-z,A-Z中随机获取一项
const getPassItem = () => confirmItem()[getIndex()];
let arr = []
arr.push(...confirmItem())
arrlengthadd()
function arrlengthadd() {
if (arr.length < 8) {
arr.push(getPassItem())
arrlengthadd()
} else {
return
}
}
return arr.toString().replace(/,/g, '')
}