Created
July 3, 2015 12:51
-
-
Save joshhunt/0b4e28a518643c1a7608 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| randomChoice = (items) -> | |
| item = items[Math.floor(Math.random()*items.length)] | |
| shuffle = (array) -> | |
| currentIndex = array.length | |
| temporaryValue = randomIndex = null | |
| # While there remain elements to shuffle... | |
| while 0 isnt currentIndex | |
| # Pick a remaining element... | |
| randomIndex = Math.floor(Math.random() * currentIndex) | |
| currentIndex -= 1 | |
| # And swap it with the current element. | |
| temporaryValue = array[currentIndex] | |
| array[currentIndex] = array[randomIndex] | |
| array[randomIndex] = temporaryValue | |
| array | |
| validLetters = ['X', 'C', 'K'] | |
| validNumbers = ['3', '4', '7'] | |
| makeCode = -> | |
| code = [ | |
| randomChoice validLetters | |
| randomChoice validLetters | |
| randomChoice validNumbers | |
| randomChoice validNumbers | |
| randomChoice validNumbers | |
| randomChoice validNumbers | |
| randomChoice validNumbers | |
| randomChoice validNumbers | |
| ] | |
| shuffle(code).join('') | |
| # Now actually make a bunch | |
| for i in [0...20] | |
| console.log makeCode() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment