<script>
function yanzheng(length) {
var charSet = ''
var result = ''
for (let i = 0; i < length; i++) {
var suiji = parseInt(Math.random() * 3)
if (suiji == 0) {
charSet = String.fromCharCode(parseInt(Math.random() * (58 - 48) + 48))//随机ASCII转为数字
}
if (suiji == 1) {
charSet = String.fromCharCode(parseInt(Math.random() * (91 - 65) + 65))//随机ASCII转为大写
}
if (suiji == 2) {
charSet = String.fromCharCode(parseInt(Math.random() * (123 - 97) + 97))//随机ASCII转为小写
}
result += charSet
}
return result
}
console.log(yanzheng(4));
</script>