Here you can find the source of getPoisson(double lambda, Random rng)
Parameter | Description |
---|---|
lambda | Lambda parameter |
public static int getPoisson(double lambda, Random rng)
//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; } }