/** * Returns a random number from the distribution. */ public int nextInt() { return generateBinomial(n, p); }
/** * Returns a random number from the distribution with the given parameters n * and p. * * @param n * the number of trials * @param p * the probability of success. * @throws IllegalArgumentException * if <tt>n*Math.min(p,1-p) <= 0.0</tt> */ public static int staticNextInt(int n, double p) { synchronized (shared) { return shared.nextInt(n, p); } }
/** * Constructs a binomial distribution. Example: n=1, p=0.5. * * @param n * the number of trials (also known as <i>sample size</i>). * @param p * the probability of success. * @param randomGenerator * a uniform random number generator. * @throws IllegalArgumentException * if <tt>n*Math.min(p,1-p) <= 0.0</tt> */ public Binomial(int n, double p, DoubleRandomEngine randomGenerator) { setRandomGenerator(randomGenerator); setNandP(n, p); }
/** * Returns the cumulative distribution function. */ private double cdfSlow(int k) { if (k < 0) throw new IllegalArgumentException(); double sum = 0.0; for (int r = 0; r <= k; r++) sum += pdf(r); return sum; }
/** * Sets the uniform random number generated shared by all <b>static</b> * methods. * * @param randomGenerator * the new uniform random number generator to be shared. */ private static void xstaticSetRandomGenerator(DoubleRandomEngine randomGenerator) { synchronized (shared) { shared.setRandomGenerator(randomGenerator); } } }
/** * Returns the cumulative distribution function. */ private double cdfSlow(int k) { if (k < 0) throw new IllegalArgumentException(); double sum = 0.0; for (int r = 0; r <= k; r++) sum += pdf(r); return sum; }
/** * Sets the uniform random number generated shared by all <b>static</b> * methods. * * @param randomGenerator * the new uniform random number generator to be shared. */ private static void xstaticSetRandomGenerator(DoubleRandomEngine randomGenerator) { synchronized (shared) { shared.setRandomGenerator(randomGenerator); } } }
/** * Constructs a binomial distribution. Example: n=1, p=0.5. * * @param n * the number of trials (also known as <i>sample size</i>). * @param p * the probability of success. * @param randomGenerator * a uniform random number generator. * @throws IllegalArgumentException * if <tt>n*Math.min(p,1-p) <= 0.0</tt> */ public Binomial(int n, double p, DoubleRandomEngine randomGenerator) { setRandomGenerator(randomGenerator); setNandP(n, p); }
/** * Returns a random number from the distribution. */ public int nextInt() { return generateBinomial(n, p); }
/** * Returns a random number from the distribution with the given parameters n * and p. * * @param n * the number of trials * @param p * the probability of success. * @throws IllegalArgumentException * if <tt>n*Math.min(p,1-p) <= 0.0</tt> */ public static int staticNextInt(int n, double p) { synchronized (shared) { return shared.nextInt(n, p); } }
/** * Returns a random number from the distribution with the given parameters n * and p; bypasses the internal state. * * @param n * the number of trials * @param p * the probability of success. * @throws IllegalArgumentException * if <tt>n*Math.min(p,1-p) <= 0.0</tt> */ public int nextInt(int n, double p) { if (n * Math.min(p, 1 - p) <= 0.0) throw new IllegalArgumentException(); return generateBinomial(n, p); }
/** * Returns a random number from the distribution with the given parameters n * and p; bypasses the internal state. * * @param n * the number of trials * @param p * the probability of success. * @throws IllegalArgumentException * if <tt>n*Math.min(p,1-p) <= 0.0</tt> */ public int nextInt(int n, double p) { if (n * Math.min(p, 1 - p) <= 0.0) throw new IllegalArgumentException(); return generateBinomial(n, p); }