Guest User

Untitled

a guest
Aug 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public static int generatorPoisson(double lambda){
  2. int x = 0;
  3. double q = Math.exp(-lambda);
  4. double s = q;
  5. double p = q;
  6. double u = generatorU();
  7. while(u > s){
  8. x++;
  9. p=p*lambda/x;
  10. s=s+p;
  11. }
  12. //System.out.println("Poisson: "+x);
  13. if(x==0){ //Client can't arive the exact second. Minimum is 1 second.
  14. x=1;
  15. }
  16. return x;
  17. }
  18.  
  19.  
  20. public static int generatorPoisson2(double lambda){
  21. int x = -1;
  22. double s = 1;
  23. double u;
  24. double q = Math.exp(-lambda);
  25. while(s>q){
  26. u = generatorU();
  27. s = s*u;
  28. x++;
  29. }
  30. if(x==0){ //Client can't arive the exact second. Minimum is 1 second.
  31. x=1;
  32. }
  33. return x;
  34. }
Add Comment
Please, Sign In to add comment