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
# See http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm | |
# written as one-liners because my REPL didn't like multiline functions this morning | |
# tested on CoffeeScript v1.0.1 | |
input = [0 .. 7] | |
swap = (input, x, y) -> [input[x], input[y]] = [input[y], input[x]] | |
rand = (x) -> Math.floor Math.random() * x | |
durst = (input) -> swap(input, i, rand i) for i in [input.length - 1 .. 1] | |
""" |