Shuffle a Javascript Array

This function shuffles a javascript array quickly and does so in one line of code.


function shuffle(o) {
	return o.sort(function() { return 0.5 - Math.random(); });
}

Example:

javascript
var n = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

n = shuffle(n);

Produces the result: 

n == [3, 5, 2, 7, 6, 8, 1, 9, 4, 2] ... or any other random set of values