Nodejs Random Number Get getRandom(low, high)

Here you can find the source of getRandom(low, high)

Method Source Code

// modifying the prototype of the number objects.


Number.prototype.getRandom = function(low, high){
   //from   w  w w.  j av a  2 s  .c  om
   'use strict';
   var randomNumber;

   // hacking overloading
   if((low === undefined) || (high === undefined)){
      
      low = 1;
      high = 10;
   }

   //calculate the random number
   randomNumber = Math.round(Math.random() * (high - low)) + low;


   return randomNumber;
};

Number.prototype.easterEgg = "This is easter egg!!";

Related

  1. randomBetween(min, max)
    Math.randomBetween = function(min, max) {
      return Math.floor(Math.random()*(max-min+1)+min);
    };
    
  2. randomGaussian(mean, standardDeviation)
    Math.randomGaussian = function(mean, standardDeviation) {
      if (Math.randomGaussian.nextGaussian !== undefined) {
        var nextGaussian = Math.randomGaussian.nextGaussian;
        delete Math.randomGaussian.nextGaussian;
        return (nextGaussian * standardDeviation) + mean;
      } else {
        var v1, v2, s, multiplier;
        do {
          v1 = 2 * Math.random() - 1; 
    ...
    
  3. GetRandomNum(Min, Max)
    function GetRandomNum(Min, Max) {
      var Range = Max - Min;
      var Rand = Math.random();
      return (Min + Math.round(Rand * Range));
    
  4. getRandomArbitrary(min, max)
    function getRandomArbitrary(min, max) {
        return Math.random() * (max - min) + min;
    
  5. getRandom
    ===
    
  6. getRandom(low, high)
    Number.prototype.getRandom = function(low, high) {
        "use strict";    
        var randomNumber;
        if ((low === undefined) || (high === undefined)) {
            low = 1;
            high = 10;
        randomNumber = Math.round(Math.random() * (high - low)) + low;
        return randomNumber;
    ...
    
  7. getRandomInterval(min, max)
    Random.getRandomInterval(min, max){
        return Math.random() * (max - min) + min;
    
  8. getRandomNumber(min, max)
    var getRandomNumber = function (min, max){
      return Math.floor(Math.random() * max + min);
    
  9. getRandomNumberBinary()
    var getRandomNumberBinary = function() {
      var randomNumber = getRandomNumber(0, 15);
      var returnObject = { decimal: randomNumber, binario: pad(dec2bin(randomNumber), 4)}
      return returnObject;
    var getRandomNumber = function (min, max){
      return Math.floor(Math.random() * max + min);