package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
/**
* Implements Pascal random variate generators, which is a special case of the
* negative binomial generator with parameter γ equal to a positive integer.
* See {@link NegativeBinomialGen} for a description.
*
*/
public class PascalGen extends RandomVariateGenInt {
protected int n;
protected double p;
/**
* Creates a Pascal random variate generator with parameters n and p,
* using stream s.
*
*/
public PascalGen (RandomStream s, int n, double p) {
super (s, new PascalDist (n, p));
setParams (n, p);
}
/**
* Creates a new generator for the distribution dist, using
* stream s.
*
*/
public PascalGen (RandomStream s, PascalDist dist) {
super (s, dist);
if (dist != null)
setParams (dist.getN(), dist.getP());
}
/**
* Generates a new variate from the Pascal distribution,
* with parameters n = n and p = p, using stream s.
*
*/
public static int nextInt (RandomStream s, int n, double p) {
return PascalDist.inverseF (n, p, s.nextDouble());
}
/**
* Returns the parameter n of this object.
*
*/
public int getN() {
return n;
}
/**
* Returns the parameter p of this object.
*
*
*/
public double getP() {
return p;
}
/**
* Sets the parameter n and p of this object.
*
*/
protected void setParams (int n, double p) {
if (p < 0.0 || p > 1.0)
throw new IllegalArgumentException ("p not in [0, 1]");
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
this.p = p;
this.n = n;
}
}
Ads help maintain this website.