Skip to content

Instantly share code, notes, and snippets.

@ankitbtanna
Created February 28, 2024 04:36
Show Gist options
  • Save ankitbtanna/3fcff4a0e1f93404c101f3e32af8a03d to your computer and use it in GitHub Desktop.
Save ankitbtanna/3fcff4a0e1f93404c101f3e32af8a03d to your computer and use it in GitHub Desktop.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generateGame() {
const game = {
numbers: [],
powerball: generateRandomNumber(1, 20)
};
while (game.numbers.length < 7) {
const randomNumber = generateRandomNumber(1, 35);
if (!game.numbers.includes(randomNumber)) {
game.numbers.push(randomNumber);
}
}
return game;
}
rl.question('Enter the number of games (between 1 and 18): ', (numGames) => {
numGames = parseInt(numGames);
if (numGames < 1 || numGames > 18 || isNaN(numGames)) {
console.log('Error: Please enter a number between 1 and 18.');
rl.close();
return;
}
const games = [];
for (let i = 0; i < numGames; i++) {
games.push(generateGame());
}
console.log('Generated Games:');
games.forEach((game, index) => {
console.log(`Game ${index + 1}: ${game.numbers.join(', ')} Powerball: ${game.powerball}`);
});
rl.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment