Nodejs Array Random randomize()

Here you can find the source of randomize()

Method Source Code

/**//from   ww w .  j  a v a  2  s  . c  om
 * @returns {array} New array with randomized items
 * FIXME destroys this!
 */
Array.prototype.randomize = function() {
   var result = [];
   while (this.length) {
      var index = this.indexOf(this.random());
      result.push(this.splice(index, 1)[0]);
   }
   return result;
}

Related

  1. randomPick()
    Array.prototype.randomPick = function () {
        return this[Math.floor(Math.random()*this.length)];
    };
    
  2. randomPick()
    Array.prototype.randomPick = function() {
      var index = Math.floor(Math.random() * this.length);
      return this[index];
    
  3. randomRemove()
    Array.prototype.randomRemove = function () {
      return this.splice(Math.floor(Math.random() * this.length), 1)[0];
    
  4. random_item()
    'use strict';
    Array.prototype.random_item = function () {
        return this[Math.floor(Math.random() * this.length)];
    };
    var printError = function (msg) {
        var newline = document.createElement('br');
        var content = document.createTextNode(msg);
        var messages = document.getElementById('messages');
        messages.appendChild(content);
    ...
    
  5. randomise()
    Array.prototype.randomise = function() {
        return this.sort(function() { return 0.5 - Math.random() });
    
  6. randomize()
    Array.prototype.randomize = Array.prototype.randomize || function() {
      var result = [];
      var clone = this.slice();
      while (clone.length) {
        var index = clone.indexOf(clone.random());
        result.push(clone.splice(index, 1)[0]);
      return result;
    
  7. randomize()
    Array.prototype.randomize = function() {
        if (this.length < 2) {
            return this;
        var items = Array.from(this);
        var newArr = [];
        while (items.length > 0) {
            var entry = items.random();
            newArr.push(entry);
    ...
    
  8. randomize()
    function range(from, to) {
      var result = []
      for(var i = from; i <= to; i++) {
        result.push(i)
      return result
    Array.prototype.randomize = function() {
      this.sort(function(){ return (Math.round(Math.random()) - 0.5) })
    ...
    
  9. randomize()
    Array.prototype.randomize = function(){
      var size = this.length;
      var itensInArray = 0;
      var newArray = [];
      var emptyObject = {}; 
      this.forEach(function(){ newArray.push(emptyObject); }); 
      this.forEach(function(item){
        var index = Math.randomInt(0, size - 1);
        while(newArray[index] != emptyObject) {
    ...