How can I shuffle an array\'s values in the most efficient manner possible?
Each element is just a string containing HTML.
This is the one I use. It gives a random number to each element, sorts the array by those random numbers (moving the real values along) and then removes the random numbers again. It seems to be equally distributed, but I've not mathematically proven it yet.
arr = arr.map(function(v) {
return [v, Math.random()];
}).sort(function(a, b) {
return a[1] - b[1];
}).map(function(v) {
return v[0];
});
http://jsfiddle.net/XQRFt/ - Test results (might be slow)