Written on
·
207
5
const SETTING = {
name : "LUCKY LOTTO",
count : 6,
maxNumber : 45
};
const {count, maxNumber} = SETTING;
const lotto = new Set();
function getRandomNumbers(maxNum) {
while(lotto.size < count) {
const randNum = Math.floor(Math.random() * (maxNum - 1)) + 1;
if (!lotto.has(randNum)) {
lotto.add(randNum);
}
}
}
getRandomNumbers(maxNumber);
lotto.forEach(n => {console.log(n)});
Answer