-5

please I saw a method that implements the Poisson distribution function to generate random numbers and I have no idea how to run it. Can someone please help me with the main method that can print the random numbers? Below are the codes:

 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;

}

Thank you.

Miji05
  • 11
  • 4

1 Answers1

0

What about:

public class Test {
  public static int getPoisson(double lambda) { ... your code

  public static void main(String[] args) {
    System.out.println("Got: " + getPoisson(0.1));
  }
}

But the real answer is: when you want to learn programming; you do that by studying and learning.

Thus the real answer here --- turn here and start reading and trying. Yourself.

GhostCat
  • 137,827
  • 25
  • 176
  • 248