Tuesday, May 09, 2006

Shuffle Array

shuffleArray = function (theArray) {
// (Shuffle 10 times just for the heck of it)
for (i=0; i<10; i++) {
theArray.sort(function (a, b) {
return random(3)-1;
});
}
};




Array.prototype.shuffle = function() {
var Arr2 = new Array();
while (this.length>0) {
Arr2.push(this.splice(Math.round((this.length-1)*Math.random()), 1));
}
return Arr2;
};
theSlides=[1,2,3,4]
theSlides.shuffle();

No comments: