Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View undecided's full-sized avatar

Matthew Bennett-Lovesey undecided

View GitHub Profile
@undecided
undecided / fisher_yates_shuffle.coffee
Last active January 21, 2016 14:36 — forked from CurtisHumphrey/fisher_yates_shuffle.coffee
Fisher-Yates shuffle (in-place) in coffeescript
###
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]]
@