sure... here's a randomize protocol for the Array class. just say Pix.randomize(); and it's all ready to go...
the code shows how to use it.
Code:
<script language="javascript">
Array.prototype.randomize = function() {
var i, r, hold;
for (i = 0; i < this.length; i++) {
r = Math.floor(Math.random() * this.length);
hold = this[i];
this[i] = this[r];
this[r] = hold;
}
}
var arr = new Array(1, 2, 3, 4, 5, 6);
arr.randomize();
alert(arr.join());
</script>
|