Skip to content

Instantly share code, notes, and snippets.

@carloscabo
Created January 30, 2013 08:34
Show Gist options
  • Save carloscabo/4671669 to your computer and use it in GitHub Desktop.
Save carloscabo/4671669 to your computer and use it in GitHub Desktop.
#js #random #shuffle #array #fisher #yates Shuffles array's elements
var fisherYates = function( myArray ) {
var i = myArray.length, j, tempi, tempj;
if ( i == 0 ) return false;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
tempi = myArray[i];
tempj = myArray[j];
myArray[i] = tempj;
myArray[j] = tempi;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment