Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int generatorPoisson(double lambda){
- int x = 0;
- double q = Math.exp(-lambda);
- double s = q;
- double p = q;
- double u = generatorU();
- while(u > s){
- x++;
- p=p*lambda/x;
- s=s+p;
- }
- //System.out.println("Poisson: "+x);
- if(x==0){ //Client can't arive the exact second. Minimum is 1 second.
- x=1;
- }
- return x;
- }
- public static int generatorPoisson2(double lambda){
- int x = -1;
- double s = 1;
- double u;
- double q = Math.exp(-lambda);
- while(s>q){
- u = generatorU();
- s = s*u;
- x++;
- }
- if(x==0){ //Client can't arive the exact second. Minimum is 1 second.
- x=1;
- }
- return x;
- }
Add Comment
Please, Sign In to add comment