Negotiable Paleobotanist Missions
    Have ideas to improve npm?Join in the discussion! »

    jsboxmuller

    1.1.1 • Public • Published

    Box-Muller algorithm for generating normally distributed pseudo-random samples.

    Installation

    npm install --save jsboxmuller

    Usage

    Module exports a single function that returns pseudorandom numbers from normal distribution. Function takes two optional parameters:

    Parameter Description
    mean Mean value for random variable
    variance Variance of the distribution

    If parameters are skipped, function will generate numbers from distribution with mean value of 0.0 and unit variance.

    const bm = require('jsboxmuller');
     
    let a = new Array(100);
    for(let i=0; i<100; ++i) {
      a[i] = bm();
    }
     
    // Array contains values from normal distribution with mean 0.0 and variance 1.0
    console.log(a);
     
    // x and y in distribution with mean 12.0 and variance 0.2
    let x = bm(12, 0.2); 
    let y = bm() * 0.2 + 12;

    Install

    npm i jsboxmuller

    DownloadsWeekly Downloads

    47

    Version

    1.1.1

    License

    ISC

    Last publish

    Collaborators

    • avatar