如何隨機排序陣列, 可以利用這篇文章的 shuffle 函數: http://javascript.about.com/library/blsort4.htm
利用隨機交換的方式, 將陣列排出結果, 程式碼如下:
代碼: 選擇全部
Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1));
while (s.length) this.push(s.pop());
return this;
}