Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Created December 14, 2015 14:59
Show Gist options
  • Save Dammmien/61a3346f1bf670161619 to your computer and use it in GitHub Desktop.
Save Dammmien/61a3346f1bf670161619 to your computer and use it in GitHub Desktop.
Shuffle an array with the Fisher–Yates shuffle in javascript
function shuffle( a ) {
var m = a.length, t, i;
while ( m ) {
i = Math.floor( Math.random() * m-- );
t = a[ m ];
a[ m ] = a[ i ];
a[ i ] = t;
}
return a;
}
shuffle( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment