Last active
April 22, 2017 21:46
-
-
Save niklasramo/f7746e43329f544257c1cf1ffb8c7830 to your computer and use it in GitHub Desktop.
Simple lotto numbers generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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