Skip to content

Instantly share code, notes, and snippets.

@yuanyan
Created May 29, 2011 06:12
Show Gist options
  • Save yuanyan/997516 to your computer and use it in GitHub Desktop.
Save yuanyan/997516 to your computer and use it in GitHub Desktop.
Poisson distribution
//Poisson distribution
//http://en.wikipedia.org/wiki/Poisson_distribution
function poisson(expectvalue){
var n = 0, //循环计数
limit = Math.exp(-expectvalue), // 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