Nodejs Array Random random()

Here you can find the source of random()

Method Source Code

"use strict";/*from  ww  w  . j ava  2s  .com*/
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();
  });
};

Related

  1. random()
    Array.prototype.random = function() { 
        return this[Math.floor(Math.random() * this.length)];
    };
    
  2. random()
    Array.prototype.random = function() { 
      return this[Math.rand(0, this.length)]; 
    
  3. random()
    Array.prototype.random = Array.prototype.random || function() {
      if (!this.length) { return null; }
      return this[Math.floor(ROT.RNG.getUniform() * this.length)];
    
  4. 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)];
    };
    ...
    
  5. random()
    var colors = ["#FFBF00", "#0080FF","#01DF3A","#FF0080"]
    Array.prototype.random = function(){
      return this[Math.floor(this.length * Math.random())]
    
  6. random()
    Array.prototype.random = function() {
      return this[ Math.floor(Math.random() * this.length) ];
    };
    
  7. random()
    Array.prototype.random = function () {
      return this[Math.floor((Math.random()*this.length))];
    
  8. random()
    Array.prototype.random = function() {
      return this[Math.floor((this.length-1)*Math.random())];
    };
    
  9. random()
    function XHR(method, path, data, callback) {
      var xhr = new XMLHttpRequest();
      xhr.open(method, path, true);
      xhr.onreadystatechange = function() {
        if (xhr.readyState != 4) return;
        callback(xhr.status, xhr.responseText);
      xhr.send(data);
    function getPos(obj) {
      var curleft = 0, curtop = 0;
      if (obj.offsetParent)
        do {
          curleft += obj.offsetLeft;
          curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
      return {x: curleft, y: curtop};
    function toRangeOrMiddle(a, x ,b) {
      if (b < a) return (a+b)/2;
      if (x < a) return a;
      if (x > b) return b;
      return x;
    Array.prototype.random = function() {
      return this[Math.random()*this.length|0];
    window.onerror = function(errorMsg, url, lineNumber) {
      var msg = "Error happened on <"+url+
        "\n> on line "+lineNumber+":\n"+
        errorMsg;
      console.log(msg);