package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;


/**
 * This class implements random variate generators for the 
 * hypergeometric distribution. Its mass function is
 * 
 * 

*
* p(x) = nCr(m, x)nCr(l - m, k - x)/nCr(l, k)        for x = max(0, k - l + m),..., min(k, m) *

* where nCr(n, x) is the number of possible combinations when choosing * x elements among a set of n elements, * m, l and k are integers that satisfy 0 < m <= l and * 0 < k <= l. * *

* The generation method is inversion using the chop-down algorithm * */ public class HypergeometricGen extends RandomVariateGenInt { private int m; private int l; private int k; /** * Creates a hypergeometric generator with * parameters m = m, l = l and k = k, * using stream s. * */ public HypergeometricGen (RandomStream s, int m, int l, int k) { super (s, new HypergeometricDist (m, l, k)); setParams (m, l, k); } /** * Creates a new generator for distribution dist, * using stream s. * */ public HypergeometricGen (RandomStream s, HypergeometricDist dist) { super (s, dist); if (dist != null) setParams (dist.getM(), dist.getL(), dist.getK()); } /** * Generates a new variate from the hypergeometric distribution with * parameters m = m, l = l and k = k, * using stream s. * */ public static int nextInt (RandomStream s, int m, int l, int k) { return HypergeometricDist.inverseF (m, l, k, s.nextDouble()); } /** * Returns the m associated with this object. * */ public int getM() { return m; } /** * Returns the l associated with this object. * */ public int getL() { return l; } /** * Returns the k associated with this object. * * */ public int getK() { return k; } /** * Sets the parameter n and p of this object. * */ protected void setParams (int m, int l, int k) { if (l <= 0) throw new IllegalArgumentException ("l must be greater than 0"); if (m <= 0 || m > l) throw new IllegalArgumentException ("m is invalid: 1<=m l) throw new IllegalArgumentException ("k is invalid: 1<=k

Ads help maintain this website.