package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.probdist.*;
import umontreal.iro.lecuyer.rng.*;
   
/**
 * This class implements random variate generators having the Poisson 
 * distribution.  Its mass function is
 * 
 * 

*
* p(x) = e-λλx/(x!) for x = 0, 1,... *

* where * λ > 0 is a real valued parameter equal to the mean. * *

* No local copy of the parameter λ = lambda * is maintained in this class. * The (non-static) nextInt method simply calls inverseF on the * distribution. * */ public class PoissonGen extends RandomVariateGenInt { protected double lambda; /** * Creates a Poisson random variate generator with * parameter λ = lambda, using stream s. * */ public PoissonGen (RandomStream s, double lambda) { super (s, new PoissonDist (lambda)); setParams (lambda); } /** * Creates a new random variate generator using the Poisson * distribution dist and stream s. * */ public PoissonGen (RandomStream s, PoissonDist dist) { super (s, dist); if (dist != null) setParams (dist.getLambda()); } /** * A static method for generating a random variate from a * Poisson distribution with parameter λ = lambda. * */ public static int nextInt (RandomStream s, double lambda) { return PoissonDist.inverseF (lambda, s.nextDouble()); } /** * Returns the λ associated with this object. * * */ public double getLambda() { return lambda; } /** * Sets the parameter λ = lam of this object. * */ protected void setParams (double lam) { if (lam <= 0.0) throw new IllegalArgumentException ("lambda <= 0"); this.lambda = lam; } }

Ads help maintain this website.