package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
/**
* This class implements random variate generators for the Cauchy
* distribution. The density is
*
*
*
* f (x) = β/(π[(x - α)2 + β2]) for - ∞ < x < ∞,
*
* where β > 0.
*
*
* The (non-static) nextDouble method simply calls
* inverseF on the distribution.
*
*/
public class CauchyGen extends RandomVariateGen {
protected double alpha;
protected double beta;
/**
* Creates a Cauchy random variate generator with parameters
* α = alpha and β = beta,
* using stream s.
*
*/
public CauchyGen (RandomStream s, double alpha, double beta) {
super (s, new CauchyDist(alpha, beta));
setParams(alpha, beta);
}
/**
* Creates a Cauchy random variate generator with parameters
* α = 0 and β = 1, using stream s.
*
*/
public CauchyGen (RandomStream s) {
this (s, 0.0, 1.0);
}
/**
* Create a new generator for the distribution dist,
* using stream s.
*
*/
public CauchyGen (RandomStream s, CauchyDist dist) {
super (s, dist);
if (dist != null)
setParams(dist.getAlpha(), dist.getBeta());
}
/**
* Generates a new variate from the Cauchy distribution with parameters
* α = alpha and β = beta, using stream s.
*
*/
public static double nextDouble (RandomStream s,
double alpha, double beta) {
return CauchyDist.inverseF (alpha, beta, s.nextDouble());
}
/**
* Returns the parameter α of this object.
*
*/
public double getAlpha() {
return alpha;
}
/**
* Returns the parameter β of this object.
*
*/
public double getBeta() {
return beta;
}
protected void setParams (double alpha, double beta) {
if (beta <= 0.0)
throw new IllegalArgumentException ("beta <= 0");
this.alpha = alpha;
this.beta = beta;
}
}
Ads help maintain this website.