Easy way to Randomize an Array.

Here is the sample code to shuffle the contents of an array

// Here is a simple function for randomizing the array
function randomsort(a, b) {
        return Math.random()>.5 ? -1 : 1;
}
//usage example
var arr = [1, 2, 3, 4, 5];
arr.sort(randomsort);
trace(arr);
//traces 4,3,1,5,2

Leave a Reply