How to Generate Random Numbers: Poisson Distribution

From Q
Jump to: navigation, search

Create a new JavaScript Variable with the following Expression, where you replace 5 with your desired mean:

var mean = 5;

var L = Math.exp(-mean);
var p = 1.0;
var k = 0;

do {
    k++;
    p *= Math.random();
} while (p > L);

k - 1;

This example is based upon the first answer on stackoverflow.

See Also