Created
May 29, 2011 06:12
-
-
Save yuanyan/997516 to your computer and use it in GitHub Desktop.
Poisson distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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