Skip to content

Instantly share code, notes, and snippets.

@tanshio
Created July 10, 2014 02:16
Show Gist options
  • Save tanshio/2fdd114b1b74eb2972c8 to your computer and use it in GitHub Desktop.
Save tanshio/2fdd114b1b74eb2972c8 to your computer and use it in GitHub Desktop.
Fisher–Yates
shaffle = function(arr){
var n = arr.length;
for(var i = n - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment