IT/JS + Jquery
[JavaScript] 숫자 + 영문자 난수 만들기
시린스
2024. 4. 12. 14:24
반응형
C#으로 되어있는 것은 만들었었는데 JavaScript로 되어있는 것은 따로 없어서 작성 하게 되었습니다.
strRandomChar에서 문자 혹은 숫자만 걷어낸다면 숫자난수 , 문자난수를 구현 할 수 있습니다.
function _getRandomValue(Length){
let result = '';
let counter = 0;
const strRandomChar = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789';
const strRandomCharLength = strRandomChar.length;
while (counter < Length) {
result += strRandomChar.charAt(Math.floor(Math.random() * strRandomCharLength));
counter += 1;
}
return result;
}