/** * Returns a random number from the distribution with the given mean. */ public static int staticNextInt(double mean) { synchronized (shared) { shared.setMean(mean); return shared.nextInt(); } }
/** * Returns a random number from the distribution with the given mean. */ public static int staticNextInt(double mean) { synchronized (shared) { shared.setMean(mean); return shared.nextInt(); } }
/** * Returns a random number from the distribution; bypasses the internal * state. */ public int nextInt(int n, double p) { /*********************************************************************** * * Negative Binomial Distribution - Compound method * * * ***************************************************************** * * FUNCTION: - nbp samples a random number from the Negative * Binomial * distribution with parameters r (no. of * failures given) and p * (probability of success) * valid for r > 0, 0 < p < 1. * If G from * Gamma(r) then K from Poiss(pG/(1-p)) * is NB(r,p)--distributed. * * REFERENCE: - J.H. Ahrens, U. Dieter (1974): Computer methods * for * sampling from gamma, beta, Poisson and * binomial distributions, * Computing 12, 223--246. * SUBPROGRAMS: - drand(seed) ... * (0,1)-Uniform generator with * unsigned long integer *seed * - * Gamma(seed,a) ... Gamma generator for a > 0 * unsigned long *seed, * double a * - Poisson(seed,a) ...Poisson generator for a > 0 * * unsigned long *seed, double a. * * **********************************************************************/ double x = p / (1.0 - p); double p1 = p; double y = x * this.gamma.nextDouble(n, 1.0); return this.poisson.nextInt(y); }
/** * Returns a random number from the distribution; bypasses the internal * state. */ public int nextInt(int n, double p) { /*********************************************************************** * * Negative Binomial Distribution - Compound method * * * ***************************************************************** * * FUNCTION: - nbp samples a random number from the Negative * Binomial * distribution with parameters r (no. of * failures given) and p * (probability of success) * valid for r > 0, 0 < p < 1. * If G from * Gamma(r) then K from Poiss(pG/(1-p)) * is NB(r,p)--distributed. * * REFERENCE: - J.H. Ahrens, U. Dieter (1974): Computer methods * for * sampling from gamma, beta, Poisson and * binomial distributions, * Computing 12, 223--246. * SUBPROGRAMS: - drand(seed) ... * (0,1)-Uniform generator with * unsigned long integer *seed * - * Gamma(seed,a) ... Gamma generator for a > 0 * unsigned long *seed, * double a * - Poisson(seed,a) ...Poisson generator for a > 0 * * unsigned long *seed, double a. * * **********************************************************************/ double x = p / (1.0 - p); double p1 = p; double y = x * this.gamma.nextDouble(n, 1.0); return this.poisson.nextInt(y); }
/** * Returns a random number from the distribution; bypasses the internal * state. */ public int nextInt(double theMean) { /*********************************************************************** * * Poisson Distribution - Patchwork Rejection/Inversion * * * ***************************************************************** * * For parameter my < 10 Tabulated Inversion is applied. * For my >= 10 * Patchwork Rejection is employed: * The area below the histogram * function f(x) is rearranged in * its body by certain point * reflections. Within a large center * interval variates are sampled * efficiently by rejection from * uniform hats. Rectangular immediate * acceptance regions speed * up the generation. The remaining tails are * covered by * exponential functions. * * **********************************************************************/ DoubleRandomEngine gen = this.randomGenerator; double my = theMean; double t, g, my_k; double gx, gy, px, py, e, x, xx, delta, v; int sign; // static double p,q,p0,pp[36]; // static long ll,m; double u; int k, i; if (my < SWITCH_MEAN) { // CASE B: Inversion- start new table and
/** * Returns a random number from the distribution; bypasses the internal * state. */ public int nextInt(double theMean) { /*********************************************************************** * * Poisson Distribution - Patchwork Rejection/Inversion * * * ***************************************************************** * * For parameter my < 10 Tabulated Inversion is applied. * For my >= 10 * Patchwork Rejection is employed: * The area below the histogram * function f(x) is rearranged in * its body by certain point * reflections. Within a large center * interval variates are sampled * efficiently by rejection from * uniform hats. Rectangular immediate * acceptance regions speed * up the generation. The remaining tails are * covered by * exponential functions. * * **********************************************************************/ DoubleRandomEngine gen = this.randomGenerator; double my = theMean; double t, g, my_k; double gx, gy, px, py, e, x, xx, delta, v; int sign; // static double p,q,p0,pp[36]; // static long ll,m; double u; int k, i; if (my < SWITCH_MEAN) { // CASE B: Inversion- start new table and