If you are attempting to shuffle a deck of cards, I have found this function to be useful:
function fisherYates (myArray) {
var i = myArray.length;
while ( i-- ) {
var j = Math.floor( Math.random() * ( i + 1 ) );
var tempi = myArray[i];
var tempj = myArray[j];
myArray[i] = tempj;
myArray[j] = tempi;
}
}
usage:
myArray = [1,2,3,4,5];
fisherYates(myArray);