package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
/**
* This class implements random variate generators for the
* exponential distribution. The density is
*
*
*
* f (x) = λe-λx for x >= 0,
*
* where
* λ > 0.
*
*
* The (non-static) nextDouble method simply calls inverseF on the
* distribution.
*
*/
public class ExponentialGen extends RandomVariateGen {
protected double lambda;
/**
* Creates an exponential random variate generator with
* parameter λ = lambda, using stream s.
*
*/
public ExponentialGen (RandomStream s, double lambda) {
super (s, new ExponentialDist(lambda));
setParams (lambda);
}
/**
* Creates a new generator for the exponential
* distribution dist and stream s.
*
*/
public ExponentialGen (RandomStream s, ExponentialDist dist) {
super (s, dist);
if (dist != null)
setParams (dist.getLambda());
}
/**
* Uses inversion to generate a new exponential variate
* with parameter λ = lambda, using stream s.
*
*/
public static double nextDouble (RandomStream s, double lambda) {
return ExponentialDist.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.