요즘엔 거의 쓰이지 않는다고 생각했는데....
필요한 사람이 있다닝.... 다시 한번 만들어 본당.
그저 랜덤함수로 주민번호 형태를 만들다가 마지막 자리수만
주민번호 생성 알고리즘대로 나오는 숫자를 넣으면 그만이이당. 그렇당
주석을 마니 마니 다러노아쓰니 참꼬 참고하도록 하장!
주민번호생성.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>E7E-272</title> </head> <body> <div style="text-align: center; border: 10px groove gold"> <h2>영시니 주민번호 생성기</h2> <hr /> <button onclick="dispJumin()">눌러방방</button> <div id="disp" style="height: 400px; overflow: auto"></div> </div> <script> const disp = document.querySelector("#disp"); function dispJumin() { let h1Tag = document.createElement("h1"); let juminBunho = fakeJuminBunho(); if (juminBunho.startsWith("0")) { h1Tag.style.backgroundColor = "black"; h1Tag.style.color = "yellow"; } h1Tag.innerHTML = juminBunho; disp.appendChild(h1Tag); disp.scrollTo(0, disp.scrollHeight); } // 주민번호 체크로직대로 마지막 체크넘버만 잘 구하면 됨 // 지역코드는 0~95까지 두자리 // 총 13자리 중 12자리에 2,3,4,5,6,7,8,9,2,3,4,5를 각각 곱해서 더한다. // 11에서 (총합을 11 나눈 나머지)를 뺀 값이 최종값 // 단 그 값이 10이나 11이면 두 자리이니깡, 0, 1로 정한다. // 그저 흐름대로 그대로 구현만 하면 됨 // 1자리 숫자를 2자리 문자열로 바꿔주는 util 함수(내맘) function format2(pNum) { if (pNum < 10) { return `0${pNum}`; } return `${pNum}`; } // 진짜로 확인되는 가짜 주민번호 생성 함수 function fakeJuminBunho() { // 랜덤 성별 코드 생성 // 1~4 (* 외국인 제외 2000이후 생) let sungbyul = Math.ceil(Math.random() * 4); // 랜덤 생년 2자리 생성 65년생 ~ 99년생 let year = format2(Math.round(Math.random() * 34) + 65); // 만약 성별 코드가 3이나 4이면, 곧 2000년 이후 생이면, 00~05, 현재 20대 if ([3, 4].includes(sungbyul)) { year = format2(Math.round(Math.random() * 5)); } // 랜덤 월 2자리 생성 Month 1~12 let month = format2(Math.ceil(Math.random() * 12)); // 날짜 생성, 달마다 다른 마지막 날짜 넘지 않게 조금 신경쓰깅 let imsiDate; if (year.startsWith("0")) { imsiDateStr = `20${year}-${month}-01`; // 마지막 날짜를 구하기위함 } else { imsiDateStr = `19${year}-${month}-01`; // 같은 맥락 } let ckDate = new Date(imsiDateStr); ckDate.setMonth(ckDate.getMonth() + 1); // 다음달로 세팅 ckDate.setDate(0); // 1일이 시작일이라, 0이면 전달 마지막날로 넘어감 // 마지막 날짜를 넘기지 않는 랜덤 날짜 생성 1~ 해당월 마지막날 let date = format2(Math.ceil(Math.random() * ckDate.getDate())); // 년도 + 월 + 날짜로 생년월일 6자리 완성 let birthday = `${year}${month}${date}`; //console.log("생년월일6자리:",birthday); // 성별코드 제외한 랜덤한 다섯자리 , 시도(2자리), 읍면동(2자리), 순번(1자리) let sido = format2(Math.round(Math.random() * 95)); // 00~95 let yubdong = format2(Math.ceil(Math.random() * 99)); let sunbun = Math.ceil(Math.random() * 9); // 일단 오른쪽 6자리 완성 let rightcode = `${sungbyul}${sido}${yubdong}${sunbun}`; // 생년월일 6자리와 일단 생성한 오른쪽 6자리 합치기 let bunho12 = `${birthday}${rightcode}`; //console.log("체킁12",bunho12); const multinum = "234567892345"; // 알고리즘에서 곱하라고 하는 숫자 12개 // 체크 넘버를 구하기 위한 알고리즘 대롱, 산수 시작 let sum = 0; // 각자리 곱해서 합 구하기 for (let i = 0; i < bunho12.length; i++) { sum += bunho12[i] * multinum[i]; } // 체크 넘버 구하기 let ckNum = 11 - (sum % 11); if (ckNum == 10) ckNum = 0; if (ckNum == 11) ckNum = 1; // 오른쪽 6자리에 체크넘버 합치면, 완성된 7자리 let final = `${rightcode}${ckNum}`; console.log("완성: ", `${birthday}-${final}`); return `${birthday}-${final}`; } </script> </body> </html>
결과는 뻔하고 뻔하닝 줄여서 뻔뻔하다 하겠당.
더미 데이터 생성시에 위 함수만 뽑아서 입맛에 맞게 수정해 쓰면 그만 일거시다.
https://www.youtube.com/watch?v=BFneXcaG_kU
ag-grid 간단 사용법(사용법 업그레이드!) (8) | 2025.04.07 |
---|---|
AJAX 파일(blob)다운로드 사용법 정리(axios,fetch,jquery, vanilla) (2) | 2025.03.20 |
노션에 등장 블록 에디터 (editor.js) (6) | 2025.03.12 |
네이버 오늘 날씨 한번 가져와 보깅깅 (2) | 2025.03.12 |
faker-js 이용 가짜(Dummy) 데이터 마궁 맹글깅(쪼메 바뀜) (0) | 2024.10.24 |