prand function

int prand (
  1. Random rand,
  2. double z
)

Return a random variable following a Poisson distribution of parameter z.

Implementation

int prand(Random rand, double z) {
  if (z <= 1.0e-10) {
    return 0;
  }
  if (z > 100) {
    return ((sqrt(z) * grand(rand)) + z).toInt();
  }
  int k = 0;
  double y = exp(-z);
  for (double s = 1.0; s >= y; ++k) {
    s *= rand.nextDouble();
  }
  return k - 1;
}