After reading through some "how to shuffle" questions on SO, I saw that this answer was generally accepted:
function shuffle (array) {
var tmp, current, top = array.length;
if(top) while(--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
return array;
}
But what would the problems be with just picking the elements in the list randomly, like I posted:
function shuffle (array) {
var result = [];
while(array.length){
var index = Math.floor(Math.random() * array.length);
result.push(array.splice(index, 1)[0]);
}
return result;
}