Last active
August 29, 2015 14:27
-
-
Save yuheiy/822fb8ae0062e15c630c to your computer and use it in GitHub Desktop.
shuffle arranges in javascript. Fisher-Yates.
This file contains 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(list) { | |
var i = list.length; | |
while (--i) { | |
var j = Math.floor(Math.random() * (i + 1)); | |
if (i == j) continue; | |
var k = list[i]; | |
list[i] = list[j]; | |
list[j] = k; | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment