Nodejs Array Shuffle shuffle(b)

Here you can find the source of shuffle(b)

Method Source Code

function random(min, max) 
{
  return Math.floor(Math.random() * (max - min + 1)) + min; 
};

function getRandomColor()
{
  return 'rgb(' + random(0, 255) + ', ' + random(0, 255) + ', ' + random(0, 255) + ')';
};

function generateRandomSymbols()
{
  if (!window.symbols) 
  {//from  w ww  .java  2 s.  c o m
    window.symbols = [];

    for (var i = 0; i <= 10000; i++)
    {
      symbols.push(String.fromCharCode(i));
    }    
  }
  else
    return;
};

function getRandomSymbol()
{
  generateRandomSymbols();

  return symbols[random(0, symbols.length - 1)];
};

Array.prototype.shuffle = function(b)
{
  var i = this.length, j, t;

  while (i) 
  {
    j = Math.floor((i--) * Math.random());
    t = (b && typeof this[i].shuffle !== 'undefined') ? this[i].shuffle() : this[i];
    this[i] = this[j];
    this[j] = t;
  }

  return this;
};

Related

  1. shuffle()
    Array.prototype.shuffle = function () {
      var i = this.length,
        j, t;
      var arr = this;
      while (i--) {
        j = Math.floor((i + 1) * Math.random());
        t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    ...
    
  2. shuffle()
    Array.prototype.shuffle = function() {
        for (var j, x, i = this.length - 1; i; j = randomNumber(i), x = this[--i], this[i] = this[j], this[j] = x);
        return this;
    };
    
  3. shuffle()
    Array.prototype.shuffle = function () {
        var c = this.slice(0);
        for (var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
        if (this.compare(c)) {
            this.shuffle();
        return this;
    }; 
    
  4. shuffle()
    Array.prototype.shuffle = function(){
      var counter = this.length, temp, index;
        while (counter > 0){
          index = Math.floor(Math.random() * counter);
          counter--;
          temp = this[counter];
          this[counter] = this[index]
          this[index] = temp;
        };
    ...
    
  5. shuffle()
    Array.prototype.shuffle = function(){
      var counter = this.length, temp, index;
      while (counter > 0) {
        index = (Math.random() * counter--) | 0;
        temp = this[counter];
        this[counter] = this[index];
        this[index] = temp;
      return this;
    ...
    
  6. shuffle(maxLength)
    Array.prototype.shuffle = function (maxLength) {
        var currentIndex = this.length
        var temporaryValue;
        var randomIndex;
        var result;
        maxLength = maxLength || this.length
        while (0 !== currentIndex) {
          randomIndex = Math.floor(Math.random() * currentIndex);
          currentIndex -= 1;
    ...
    
  7. shuffle(n)
    Array.prototype.shuffle = function (n) {
        var params = [].slice.call(arguments);
        var index = -1,
            result = this,
            length = result.length,
            lastIndex = length - 1;
        while (++index < n) {
            var rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
                value = result[rand];
    ...
    
  8. shuffle(times)
    Array.prototype.shuffle = function(times) {
        if(undefined === times) times = this.length * 2;
        var temp;
        while(times--) {
            var a = Number.random(0, this.length - 1);
            var b = Number.random(0, this.length - 1);
            temp = this[a];
            this[a] = this[b];
            this[b] = temp;
    ...
    
  9. shuffleMe()
    Array.prototype.shuffleMe = function() {
        var array_length = this.length;
        var loop_no = array_length;
        while (--loop_no > 0) {
            var random_number = Math.floor(Math.random() * (loop_no + 1));
            var value = this[random_number];
            this[random_number] = this[loop_no];
            this[loop_no] = value;
        return this;
    var array = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
    var result = array.shuffleMe();
    console.log(result);