randomWord(); //34jm9e
export const randomWord = () => {
let code = ''
for (var i = 0; i < 6; i++) {
var type = getRandom(1, 3)
switch (type) {
case 1:
code += String.fromCharCode(getRandom(48, 57))// 数字
break
case 2:
code += String.fromCharCode(getRandom(65, 90))// 大写字母
break
case 3:
code += String.fromCharCode(getRandom(97, 122))// 小写字母
break
}
}
return code
}
function getRandom (min, max) {
return Math.round(Math.random() * (max - min) + min)
}
js 生成包含数字和字母的6位随机数
最新推荐文章于 2023-05-25 13:14:16 发布