Javascript Array random()
/**/*from ww w . java2 s . c om*/ * Array#random() -> Object * Returns a random item from the array instance; **/ Array.prototype.random = function() { if (!this.length) return; return this[Math.floor(Math.random() * this.length)]; };
Array.prototype.random = function() { var index = Math.floor(this.length * Math.random()); var result = this[index]; return result; } var arr = new Array(2,3,82,1,232,12,32); console.log(arr.random());/*from www. j a v a2s .com*/
// Returns a random element in the Array Array.prototype.random = function() { // Prototypes throw TypeErrors when the context or arguments are invalid if (Object.prototype.toString.call(this) !== '[object Array]') { throw new TypeError("`this` must be Array, not " + typeof this); }// w w w . ja v a 2 s. com return this[Math.floor(Math.random() * this.length)]; };
Array.prototype.random = function() { return this[Math.floor((Math.random() * this.length))]; }; Array.prototype.shuffle = function() { var m = this.length, i; while (m) {//from ww w.j a v a2 s . co m i = (Math.random() * m--) >>> 0; [this[m], this[i]] = [this[i], this[m]] } return this; };
const COLORS = [ 'grey', 'blue', 'green' ] Array.prototype.random = function () { return this[Math.floor(Math.random()*this.length)] }
/**// ww w .ja v a 2 s . c om * Returns a randomly chosen element from the array */ Array.prototype.random = function() { return this[ Math.randomInt( 0, this.length - 1 ) ]; };
/**//from www . java 2 s. c o m * @returns {any} Randomly picked item, null when length=0 */ Array.prototype.random = function() { if (!this.length) { return null; } return this[Math.floor(ROT.RNG.getUniform() * this.length)]; }
Array.prototype.random = function() { var index = Math.floor(Math.random() * this.length), found = this[index];//from w w w.j a v a2 s . c o m this.splice(index, 1); return found; };
Array.prototype.random = function(){ return this[sb.math.rand(0,this.length)]; };
// Legacy's stock Array.prototype.random = function() { return this[Math.floor(Math.random() * this.length)]; }; /*w ww. j a v a 2 s . c om*/ Array.prototype.shuffle = function() { return this.sort(function() { return Math.random() - 0.5; }); }; Function.prototype.__extends = function(superClass) { this.prototype = Object.create(superClass.prototype); }; Object._entries = function(obj) { var entry = []; for (key in obj) entry[entry.length] = [key, obj[key]]; return entry; };
/**/*from ww w. ja v a2s. co m*/ * @returns {any} Randomly picked item, null when length=0 */ Array.prototype.random = Array.prototype.random || function() { if (!this.length) { return null; } return this[Math.floor(ROT.RNG.getUniform() * this.length)]; }
Array.prototype.random = function() { if (this.length === 0) { return null; }/*from w w w . j a va 2 s . c o m*/ if (this.length === 1) { return this[0]; } return this[Math.floor(RougeLib.RNG.random() * this.length)]; };
"use strict";//www.ja va 2s . c om var cyphers, letters; exports.options = "-r, --replace"; exports.description = "Return a the current sentence, where the 'x' are replaced by random number, and the 'y'."; letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; cyphers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; Array.prototype.random = function() { return this[~~(Math.random() * this.length)]; }; exports.exec = function(given) { return given.replace(/[xy]/g, function(letter) { return (letter === "y" ? letters : cyphers).random(); }); };
/* global Game */ Array.prototype.random = function() { if (this.length === 0) { return null; }/*from ww w. j a v a2s . co m*/ if (this.length == 1) { return this[0]; } return this[Math.floor(Game.RNG.random() * this.length)]; };
Array.prototype.random = function() { return this[Math.floor((this.length-1)*Math.random())]; };