Skip to content

Instantly share code, notes, and snippets.

@emkay
Created October 10, 2010 04:37
Show Gist options
  • Save emkay/618963 to your computer and use it in GitHub Desktop.
Save emkay/618963 to your computer and use it in GitHub Desktop.
/*
* Fisher-Yates algorithm from Knuth TAOCP Vol. 2 Sec 3.4.2
*/
this.shuffle = function () {
var j = 52;
while (--j) {
var n = Math.random();
var k = Math.floor(j * n) + 1;
var temp = this.cards[j];
this.cards[j] = this.cards[k];
this.cards[k] = temp;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment