Nodejs Random Number Get randomGaussian(mean, standardDeviation)

Here you can find the source of randomGaussian(mean, standardDeviation)

Method Source Code

// http://www.ollysco.de/2012/04/gaussian-normal-functions-in-javascript.html
/**/*from   ww  w. j a  v  a2 s .  c  o m*/
  * Returns a Gaussian Random Number around a normal distribution defined by the mean
  * and standard deviation parameters.
  *
  * Uses the algorithm used in Java's random class, which in turn comes from
  * Donald Knuth's implementation of the Box?Muller transform.
  *
  * @param {Number} [mean = 0.0] The mean value, default 0.0
  * @param {Number} [standardDeviation = 1.0] The standard deviation, default 1.0
  * @return {Number} A random number
  */
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; // between -1 and 1
      v2 = 2 * Math.random() - 1; // between -1 and 1
      s = v1 * v1 + v2 * v2;
    } while (s >= 1 || s == 0);
    multiplier = Math.sqrt(-2 * Math.log(s) / s);
    Math.randomGaussian.nextGaussian = v2 * multiplier;
    return (v1 * multiplier * standardDeviation) + mean;
  }
};

Related

  1. random(min, max)
    function random(min, max) {
        return Math.floor(Math.random() * (max - min)) + min;
    
  2. random(min, max)
    function random(min, max) {
       return Math.floor(Math.random() * (max - min + 1)) + min;
    
  3. random(min, max)
    function random(min, max) {
      return Math.floor(Math.random() * max) + min;
    
  4. randomBetween(N, M)
    randomBetween = function(N, M) {
      return Math.floor(M + (1 + N - M) * Math.random());
    };
    
  5. randomBetween(min, max)
    Math.randomBetween = function(min, max) {
      return Math.floor(Math.random()*(max-min+1)+min);
    };
    
  6. GetRandomNum(Min, Max)
    function GetRandomNum(Min, Max) {
      var Range = Max - Min;
      var Rand = Math.random();
      return (Min + Math.round(Rand * Range));
    
  7. getRandomArbitrary(min, max)
    function getRandomArbitrary(min, max) {
        return Math.random() * (max - min) + min;
    
  8. getRandom
    ===
    
  9. 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;
    ...