// -*- C++ -*- // $Id$ /* * Chi^2 distribution * * This code has been adapted from RANDLIB.C 1.3, by * Barry W. Brown, James Lovato, Kathy Russell, and John Venier. * Code was originally by Ahrens and Dieter (see above). * * Adapter's notes: */ #ifndef BZ_RANDOM_CHISQUARE #define BZ_RANDOM_CHISQUARE #ifndef BZ_RANDOM_GAMMA #include #endif namespace ranlib { template class ChiSquare : public Gamma { public: typedef T T_numtype; ChiSquare(T df) : Gamma(df/2.0) // isn't this redundant with setDF call? { setDF(df); } ChiSquare(T df, unsigned int i) : Gamma(df/2.0, i) { setDF(df); } void setDF(T _df) { BZPRECONDITION(_df > 0.0); df = _df; Gamma::setMean(df/2.0); } T random() { return 2.0 * sgamma(); } protected: T sgamma() { return Gamma::random(); } T df; }; } #endif // BZ_RANDOM_CHISQUARE