Este snippet embaralha uma array:
function embaralhar(array) { var indice_atual = array.length, valor_temporario, indice_aleatorio; while (0 !== indice_atual) { indice_aleatorio = Math.floor(Math.random() * indice_atual); indice_atual -= 1; valor_temporario = array[indice_atual]; array[indice_atual] = array[indice_aleatorio]; array[indice_aleatorio] = valor_temporario; } return array; }
Seu uso:
var minha_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; embaralhar(minha_array); -> [6, 7, 5, 2, 8, 1, 0, 4, 9, 3]