Skip to content

Instantly share code, notes, and snippets.

@RafaelCosman
RafaelCosman / poisson.js
Last active December 29, 2015 15:58 — forked from yuanyan/poisson.js
Poisson distribution
//Poisson distribution
//http://en.wikipedia.org/wiki/Poisson_distribution
function poisson(expected_value){
var n = 0, //循环计数
limit = Math.exp(-expected_value), // e -v, 其中v是期望值
x = Math.random(); //生成 0-1之间随机数
while(x > limit){
n++;
x *= Math.random();;
}