/*
This program generates random lottery numbers for:
- 6 distinct numbers out of 37
- 1 distinct number out of 7 (power number)
It uses:
- Array.from() to build ranges
- Array.sort(() => Math.random() - 0.5) to shuffle
- Math.random() for the power number
- clean functions and idiomatic JavaScript style
*/
/*
pickDistinctNumbers(count, max):
Returns `count` distinct random numbers from the range 1..max.
Algorithm:
- Build an array [1, 2, ..., max]
- Shuffle it using sort(() => Math.random() - 0.5)
- Take the first `count` numbers
*/
function pickDistinctNumbers(count, max) {
const numbers = Array.from({ length: max }, (_, i) => i + 1);
numbers.sort(() => Math.random() - 0.5); // shuffle
return numbers.slice(0, count);
}
/*
pickPowerNumber(max):
Returns a single random number in the range 1..max.
*/
function pickPowerNumber(max) {
return Math.floor(Math.random() * max) + 1;
}
/*
Main program
*/
const MAIN_COUNT = 6;
const MAIN_MAX = 37;
const POWER_MAX = 7;
// Generate main numbers (distinct)
const mainNumbers = pickDistinctNumbers(MAIN_COUNT, MAIN_MAX)
.sort((a, b) => a - b);
// Generate power number
const powerNumber = pickPowerNumber(POWER_MAX);
// Output results
console.log("Main numbers (6 out of 37):", mainNumbers.join(" "));
console.log("Power number (1 out of 7):", powerNumber);
/*
run:
Main numbers (6 out of 37): 1 15 18 24 29 36
Power number (1 out of 7): 6
*/