Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Bennett-Lovesey undecided

View GitHub Profile
@undecided
undecided / fisher_yates_shuffle.coffee
Last active Jan 21, 2016 — forked from CurtisHumphrey/fisher_yates_shuffle.coffee
Fisher-Yates shuffle (in-place) in coffeescript
View fisher_yates_shuffle.coffee
###
Randomize array element order in-place.
Using Fisher-Yates shuffle algorithm.
###
Array.prototype.shuffle = ->
for i in [(@length - 1) .. 0]
j = Math.floor(Math.random() * (i + 1))
[@[i], @[j]] = [@[j], @[i]]
@
You can’t perform that action at this time.