Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- init:
- Let L ← e^(−λ), k ← 0 and p ← 1.
- do:
- k ← k + 1.
- Generate uniform random number u in [0,1] and let p ← p × u.
- while p > L.
- return k − 1.
- public static int getPoisson(double lambda) {
- double L = Math.exp(-lambda);
- double p = 1.0;
- int k = 0;
- do {
- k++;
- p *= Math.random();
- } while (p > L);
- return k - 1;
- }
- public static int getBinomial(int n, double p) {
- int x = 0;
- for(int i = 0; i < n; i++) {
- if(Math.random() < p)
- x++;
- }
- return x;
- }
- implementation 'org.kie.modules:org-apache-commons-math:6.5.0.Final'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement