Node.js examples for Array:Shuffle
Shuffle array with while loop
Array.prototype.shuffle = function() { var i = this.length, j, tempi, tempj; if ( i == 0 ) return false; while ( --i ) { j = Math.floor( Math.random() * ( i + 1 ) ); tempi = this[i];//from w w w.j ava 2 s .c o m tempj = this[j]; this[i] = tempj; this[j] = tempi; } return this; }