Created
September 9, 2012 20:47
-
-
Save MeoMix/3687181 to your computer and use it in GitHub Desktop.
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
//Randomizes the playlist and then saves it. | |
shuffle: function () { | |
var i, j, t; | |
for (i = 1; i < playlist.songs.length; i++) { | |
j = Math.floor(Math.random() * (1 + i)); // choose j in [0..i] | |
if (j !== i) { | |
t = playlist.songs[i]; // swap songs[i] and songs[j] | |
playlist.songs[i] = playlist.songs[j]; | |
playlist.songs[j] = t; | |
} | |
} | |
save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment