Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@deleteme
Created April 24, 2015 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deleteme/5412cee4e45eb937b702 to your computer and use it in GitHub Desktop.
Save deleteme/5412cee4e45eb937b702 to your computer and use it in GitHub Desktop.
# fisher yates shuffle algorithm
# http://en.wikipedia.org/wiki/Fisher–Yates_shuffle
Array::shuffle = ->
copy = @copy()
i = @length
while --i
j = Math.floor(Math.random() * (i + 1))
temp = copy[i]
copy[i] = copy[j]
copy[j] = temp
return copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment