Nodejs Array Random random()

Here you can find the source of random()

Method Source Code

/**/* w  ww. ja  v a2  s .  c o  m*/
@Name: Array.prototype.random
@Author: Paul Visco
@Version: 1.1 11/19/07
@Description: Grab a random value from the array.  The value is randomly selected each time the value is run.
@Return: Object/String/Number Returns a random value from the array.  Type is the same as the value.
@Example:
var myArray = [1,10,2,3,4,5];
var answer = myArray.random();
//answer = 4; //<--could change each time
*/
Array.prototype.random = function(){
      return this[sb.math.rand(0,this.length)];
};

Related

  1. random()
    Array.prototype.random = function () {
      return this[Math.floor((Math.random()*this.length))];
    };
    
  2. random()
    Array.prototype.random = function() {
        if (Object.prototype.toString.call(this) !== '[object Array]') {
            throw new TypeError("`this` must be Array, not " + typeof this);
        return this[Math.floor(Math.random() * this.length)];
    };
    
  3. random()
    Array.prototype.random = function() {
      return this[ Math.randomInt( 0, this.length - 1 ) ];
    };
    
  4. random()
    Array.prototype.random = function () {
        return this[ (Math.random() * this.length).floor() ];
    };
    
  5. random()
    Array.prototype.random = function() {
      if (!this.length) { return null; }
      return this[Math.floor(ROT.RNG.getUniform() * this.length)];
    
  6. random()
    Array.prototype.random = function() { 
        return this[Math.floor(Math.random() * this.length)];
    };
    
  7. random()
    Array.prototype.random = function() { 
      return this[Math.rand(0, this.length)]; 
    
  8. random()
    Array.prototype.random = Array.prototype.random || function() {
      if (!this.length) { return null; }
      return this[Math.floor(ROT.RNG.getUniform() * this.length)];
    
  9. random()
    Array.prototype.random = function() {
        if (this.length === 0) {
            return null;
        if (this.length === 1) {
            return this[0];
        return this[Math.floor(RougeLib.RNG.random() * this.length)];
    };
    ...