Skip to content

Instantly share code, notes, and snippets.

@imcotton
Created February 28, 2012 06:01
Show Gist options
  • Save imcotton/1929997 to your computer and use it in GitHub Desktop.
Save imcotton/1929997 to your computer and use it in GitHub Desktop.
Array random in CoffeeScript
Array::random = ->
[t, l] = [@concat(), @length]
while --l
r = (Math.random() * (l + 1)) | 0
[t[r], t[l]] = [t[l], t[r]]
return t
Array::random2 = ->
@sort -> Math.random() < 0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment