Skip to content

Instantly share code, notes, and snippets.

@ml242
Forked from ddgromit/fisheryates.coffee
Created August 7, 2014 01:29
Show Gist options
  • Save ml242/832aca34a096eee3f0ed to your computer and use it in GitHub Desktop.
Save ml242/832aca34a096eee3f0ed to your computer and use it in GitHub Desktop.
# Adapted from the javascript implementation at http://sedition.com/perl/javascript-fy.html
# Randomizes the order of elements in the passed in array in place.
fisherYates = (arr) ->
i = arr.length;
if i == 0 then return false
while --i
j = Math.floor(Math.random() * (i+1))
tempi = arr[i]
tempj = arr[j]
arr[i] = tempj
arr[j] = tempi
return arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment