Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Created September 9, 2012 20:47
Show Gist options
  • Save MeoMix/3687181 to your computer and use it in GitHub Desktop.
Save MeoMix/3687181 to your computer and use it in GitHub Desktop.
//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