Skip to content

Instantly share code, notes, and snippets.

@RafaelCosman
Forked from yuanyan/poisson.js
Last active December 29, 2015 15:58
Show Gist options
  • Save RafaelCosman/ded00c90b01ac15e28fb to your computer and use it in GitHub Desktop.
Save RafaelCosman/ded00c90b01ac15e28fb to your computer and use it in GitHub Desktop.
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();;
}
return n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment