/** * Returns a random number from the distribution. */ public static double staticNextDouble(double p) { synchronized (shared) { return shared.nextDouble(p); } }
/** * Constructs a Logarithmic distribution. */ public Logarithmic(double p, DoubleRandomEngine randomGenerator) { setRandomGenerator(randomGenerator); setState(p); }
/** * 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); } } }
/** * 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 Logarithmic distribution. */ public Logarithmic(double p, DoubleRandomEngine randomGenerator) { setRandomGenerator(randomGenerator); setState(p); }
/** * Returns a random number from the distribution. */ public static double staticNextDouble(double p) { synchronized (shared) { return shared.nextDouble(p); } }
/** * Returns a random number from the distribution; bypasses the internal * state. */ public double nextDouble(double a) { /*********************************************************************** * * Logarithmic Distribution - Inversion/Transformation * * * ***************************************************************** * * The algorithm combines Inversion and Transformation. * It is based on * the following fact: A random variable X from * the Logarithmic * distribution has the property that X for fixed * Y=y is Geometric * distributed with P(X=x|Y=y)=(1-y)*y^(x-1) (*) * where Y has * distribution function F(y)=ln(1-y)/ln(1-p). * So first random numbers * y are generated by simple Inversion, * then k=(long int) * (1+ln(u)/ln(y)) is a Geometric random number * and because of (*) a * Logarithmic one. * To speed up the algorithm squeezes are used as * well as the * fact, that many of the random numbers are 1 or 2 * (depending on * special circumstances). * On an IBM/PC 486 optimal * performance is achieved, if for p<.97 * simple inversion is used and * otherwise the transformation. * On an IBM/PC 286 inversion should be * restricted to p<.90. * * * ***************************************************************** * * FUNCTION: - lsk samples a random number from the * Logarithmic * distribution with * parameter 0 < p < 1 . * REFERENCE: - A.W. Kemp * (1981): Efficient generation of * logarithmically distributed * pseudo-random * variables, Appl. Statist. 30, 249-253. * SUBPROGRAMS: * - drand(seed) ... (0,1)-Uniform generator with * unsigned long * integer *seed. * * **********************************************************************/ double u, v, p, q;
/** * Returns a random number from the distribution; bypasses the internal * state. */ public double nextDouble(double a) { /*********************************************************************** * * Logarithmic Distribution - Inversion/Transformation * * * ***************************************************************** * * The algorithm combines Inversion and Transformation. * It is based on * the following fact: A random variable X from * the Logarithmic * distribution has the property that X for fixed * Y=y is Geometric * distributed with P(X=x|Y=y)=(1-y)*y^(x-1) (*) * where Y has * distribution function F(y)=ln(1-y)/ln(1-p). * So first random numbers * y are generated by simple Inversion, * then k=(long int) * (1+ln(u)/ln(y)) is a Geometric random number * and because of (*) a * Logarithmic one. * To speed up the algorithm squeezes are used as * well as the * fact, that many of the random numbers are 1 or 2 * (depending on * special circumstances). * On an IBM/PC 486 optimal * performance is achieved, if for p<.97 * simple inversion is used and * otherwise the transformation. * On an IBM/PC 286 inversion should be * restricted to p<.90. * * * ***************************************************************** * * FUNCTION: - lsk samples a random number from the * Logarithmic * distribution with * parameter 0 < p < 1 . * REFERENCE: - A.W. Kemp * (1981): Efficient generation of * logarithmically distributed * pseudo-random * variables, Appl. Statist. 30, 249-253. * SUBPROGRAMS: * - drand(seed) ... (0,1)-Uniform generator with * unsigned long * integer *seed. * * **********************************************************************/ double u, v, p, q;