Skip to content

Instantly share code, notes, and snippets.

@niklasramo
Last active April 22, 2017 21:46
Show Gist options
  • Save niklasramo/f7746e43329f544257c1cf1ffb8c7830 to your computer and use it in GitHub Desktop.
Save niklasramo/f7746e43329f544257c1cf1ffb8c7830 to your computer and use it in GitHub Desktop.
Simple lotto numbers generator
function lotto(amountOfNumbers, from, to) {
const numbers = [];
for (let i = 0; i < amountOfNumbers; i++) {
let number = null;
while (number === null || numbers.indexOf(number) > -1) {
number = Math.floor(Math.random() * (to - from + 1)) + from;
}
numbers.push(number);
}
return numbers.sort((a, b) => a - b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment