Java Random getPoisson(double lambda, Random rng)

Here you can find the source of getPoisson(double lambda, Random rng)

Description

Poisson-distributed RNG

License

Apache License

Parameter

Parameter Description
lambda Lambda parameter

Return

Poisson-distributed random number in [0,inf)

Declaration

public static int getPoisson(double lambda, Random rng) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**/* w  ww  . j av a  2 s .  c om*/
     * Poisson-distributed RNG
     * @param lambda Lambda parameter
     * @return Poisson-distributed random number in [0,inf)
     */
    public static int getPoisson(double lambda, Random rng) {
        double L = Math.exp(-lambda);
        double p = 1.0;
        int k = 0;
        if (rng == null)
            rng = new Random();
        do {
            k++;
            p *= rng.nextDouble();
        } while (p > L);
        return k - 1;
    }
}

Related

  1. generateRandomIntegerId()
  2. generateRandomNo()
  3. GenerateRandomPin()
  4. getItemID(Random r)
  5. getOreMultiplier(int fortune, Random r)
  6. getRandom()
  7. getRandom()
  8. getRandom()
  9. getRandom(Collection collection)