/** Equivalent to <tt>raw()</tt>. This has the effect that random engines can now be used as function objects, returning a random number upon function evaluation. */ public double apply(double dummy) { return raw(); } /**
/** * Returns a uniformly distributed random <tt>boolean</tt>. */ public boolean nextBoolean() { return randomGenerator.raw() > 0.5; } /**
/** * Returns a uniformly distributed random number in the closed interval <tt>[from,to]</tt> (including <tt>from</tt> and <tt>to</tt>). * Pre conditions: <tt>from <= to</tt>. */ public int nextIntFromTo(int from, int to) { return (int) ((long)from + (long)((1L + (long)to - (long)from)*randomGenerator.raw())); } /**
/** * Returns a uniformly distributed random number in the open interval <tt>(from,to)</tt> (excluding <tt>from</tt> and <tt>to</tt>). * Pre conditions: <tt>from <= to</tt>. */ public double nextDoubleFromTo(double from, double to) { return from+(to-from)*randomGenerator.raw(); } /**
/** * Returns a uniformly distributed random <tt>boolean</tt>. */ public boolean nextBoolean() { return randomGenerator.raw() > 0.5; }
/** Equivalent to <tt>raw()</tt>. This has the effect that random engines can now be used as function objects, returning a random number upon function evaluation. */ public double apply(double dummy) { return raw(); } /**
/** * Returns a uniformly distributed random number in the closed interval * <tt>[from,to]</tt> (including <tt>from</tt> and <tt>to</tt>). Pre * conditions: <tt>from <= to</tt>. */ public int nextIntFromTo(int from, int to) { return (int) ((long) from + (long) ((1L + (long) to - (long) from) * randomGenerator .raw())); }
/** * Returns a 32 bit uniformly distributed random number in the open unit interval <code>(0.0f,1.0f)</code> (excluding 0.0f and 1.0f). */ public float nextFloat() { // catch loss of precision of double --> float conversion float nextFloat; do { nextFloat = (float) raw(); } while (nextFloat>=1.0f); // --> in (0.0f,1.0f) return nextFloat; } /**
/** * Returns a uniformly distributed random number in the open interval <tt>(min,max)</tt> (excluding <tt>min</tt> and <tt>max</tt>). */ public double nextDouble() { return min+(max-min)*randomGenerator.raw(); } /**
/** * Returns a uniformly distributed random number in the open interval <tt>(from,to)</tt> (excluding <tt>from</tt> and <tt>to</tt>). * Pre conditions: <tt>from <= to</tt>. */ public double nextDoubleFromTo(double from, double to) { return from+(to-from)*randomGenerator.raw(); } /**
/** * Returns a 32 bit uniformly distributed random number in the open unit interval <code>(0.0f,1.0f)</code> (excluding 0.0f and 1.0f). */ public float nextFloat() { // catch loss of precision of double --> float conversion float nextFloat; do { nextFloat = (float) raw(); } while (nextFloat>=1.0f); // --> in (0.0f,1.0f) return nextFloat; } /**
/** * Returns a random number from the standard Logistic distribution Log(0,1). * <p> * <b>Implementation:</b> Inversion method. * This is a port of <tt>login.c</tt> from the <A HREF="http://www.cis.tu-graz.ac.at/stat/stadl/random.html">C-RAND / WIN-RAND</A> library. */ public static double nextLogistic(RandomEngine randomGenerator) { double u = randomGenerator.raw(); return(-Math.log(1.0 / u-1.0)); } /**
/** * Returns a random number from the distribution; bypasses the internal state. */ public double nextDouble(double lambda) { return - Math.log(randomGenerator.raw()) / lambda; } /**
/** * Returns a power-law distributed random number with the given exponent and lower cutoff. * @param alpha the exponent * @param cut the lower cutoff */ public static double nextPowLaw(double alpha, double cut, RandomEngine randomGenerator) { return cut*Math.pow(randomGenerator.raw(), 1.0/(alpha+1.0) ) ; } /**
/** * Returns a random number from the distribution; bypasses the internal state. */ public double nextDouble(double lambda) { return - Math.log(randomGenerator.raw()) / lambda; } /**
/** * Returns a power-law distributed random number with the given exponent and lower cutoff. * @param alpha the exponent * @param cut the lower cutoff */ public static double nextPowLaw(double alpha, double cut, RandomEngine randomGenerator) { return cut*Math.pow(randomGenerator.raw(), 1.0/(alpha+1.0) ) ; } /**
/** * Returns an erlang distributed random number with the given variance and mean. */ public static double nextErlang(double variance, double mean, RandomEngine randomGenerator) { int k = (int)( (mean * mean ) / variance + 0.5 ); k = (k > 0) ? k : 1; double a = k / mean; double prod = 1.0; for (int i = 0; i < k; i++) prod *= randomGenerator.raw(); return -Math.log(prod)/a; } /**
/** * Returns a random number from the standard Logistic distribution Log(0,1). * <p> * <b>Implementation:</b> Inversion method. * This is a port of <tt>login.c</tt> from the <A HREF="http://www.cis.tu-graz.ac.at/stat/stadl/random.html">C-RAND / WIN-RAND</A> library. */ public static double nextLogistic(RandomEngine randomGenerator) { double u = randomGenerator.raw(); return(-Math.log(1.0 / u-1.0)); } /**
/** * Returns a weibull distributed random number. * Polar method. * See Simulation, Modelling & Analysis by Law & Kelton, pp259 */ public static double nextWeibull(double alpha, double beta, RandomEngine randomGenerator) { // Polar method. // See Simulation, Modelling & Analysis by Law & Kelton, pp259 return Math.pow(beta * ( - Math.log(1.0 - randomGenerator.raw()) ), 1.0 / alpha); } /**
/** * Returns a weibull distributed random number. * Polar method. * See Simulation, Modelling & Analysis by Law & Kelton, pp259 */ public static double nextWeibull(double alpha, double beta, RandomEngine randomGenerator) { // Polar method. // See Simulation, Modelling & Analysis by Law & Kelton, pp259 return Math.pow(beta * ( - Math.log(1.0 - randomGenerator.raw()) ), 1.0 / alpha); } /**