js 무 작위 로 6 비트 인증 코드 생 성 (대소 문자, 숫자)
안녕하세요!js 는 무 작위 로 6 비트 인증 코드 (대소 문자, 숫자) 를 생 성하 고 Math. random 을 이용 하여 무 작위 수 를 생 성 합 니 다.
코드 는 다음 과 같다.
. function getRandom(min, max) {
return Math.round(Math.random() * (max - min) + min);
}
function getCode() {
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;
};
console.log(getCode());//
유 니 코드 문자 부호화 표
문자
부호화
숫자.
48-57
소문 자
97-122
대문자
65-90
여러분, 테스트 해 보 세 요!