Created
December 14, 2015 14:59
-
-
Save Dammmien/61a3346f1bf670161619 to your computer and use it in GitHub Desktop.
Shuffle an array with the Fisher–Yates shuffle in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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