-
-
Save RafaelCosman/ded00c90b01ac15e28fb 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(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