Random permutation - Node.js Number

Node.js examples for Number:Random Number

Description

Random permutation

Demo Code

/* random permutation */
Array.prototype.shuffle = function() {
  for (var i = this.length - 1; i > 0; i--) {
    var j = Math.floor(Math.random() * (i + 1));
    var temp = this[i];
    this[i] = this[j];/*from  www .  jav a 2  s.  com*/
    this[j] = temp;
  }
};

Related Tutorials