-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
로또 번호 생성기 풀이
20.10.19 22:55 작성 조회수 183
0
const SETTING = {
name: 'LUCKY LOTTO!',
count: 6,
maxNumber: 45,
};
function getRandomNumber({ count, maxNumber }) {
let lottoSet = new Set();
const minNumber = 1;
for (let i = 0; i < count; ) {
// 두 값 사이의 난수 생성 && Math.random()이 0이 출력될 확률이 낮지만 가능해서 보완 코딩 처리.
const num = parseInt(Math.random() * (maxNumber - minNumber) + minNumber);
if (!lottoSet.has(num)) {
lottoSet.add(num);
i++;
}
}
return lottoSet;
}
const colorSet = getRandomNumber(SETTING);
// console.log(colorSet.values());
let cnt = 1;
colorSet.forEach((v) => {
console.log(cnt++, v);
});
답변을 작성해보세요.
답변 0