de.jstacs.utils.random
Class RandomNumberGenerator

java.lang.Object
  extended by de.jstacs.utils.random.RandomNumberGenerator
All Implemented Interfaces:
Serializable

public class RandomNumberGenerator
extends Object
implements Serializable

Class for generating random numbers of many different distributions.

This class was written by Sundar Dorai-Raj and was downloaded from http://www.stat.vt.edu/~sundar/java/. Only a few modifications were made by Jens Keilwagen eliminating some not used variables and making the comments visible for javadoc.

RandomNumberGenerator.java Copyright (c) 2000 by Sundar Dorai-Raj

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version, provided that any use properly credits the author.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details at http://www.gnu.org

Reference. M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3--30.

Author:
Sundar Dorai-Raj Email: sdoraira@vt.edu
See Also:
Serialized Form

Constructor Summary
RandomNumberGenerator()
           
RandomNumberGenerator(long seed)
           
 
Method Summary
protected  int next(int bits)
           
 double nextBeta(double alpha, double beta)
          generates a random number from Beta(alpha,beta) (E(X)=a/(a+b) ; Var(X)=ab/[(a+b+1)(a+b)^2])
 boolean nextBoolean()
          generates a random boolean variable
 boolean nextBoolean(double p)
          generates true with probability p
 double nextChiSq()
          generates a random number from ChiSq(1) (E(X)=1 ; Var(X)=2)
 double nextChiSq(int df)
          generates a random number from ChiSq(df) (E(X)=df ; Var(X)=2*df)
 double nextChiSq(int df, double lambda)
          generates a random number from shifted-ChiSq(df) (E(X)=df+lambda ; Var(X)=2*df)
 double nextExp()
          generates a random number from Exp(1) (E(X)=1 ; Var(X)=1)
 double nextExp(double beta)
          generates a random number from Exp(beta) (E(X)=beta ; Var(X)=beta^2)
 double nextExp(double beta, double lambda)
          generates a random number from shifted-Exp(beta) (E(X)=beta+lambda ; Var(X)=beta^2)
 double nextGamma()
          generates a random number from Gamma(1,1) (E(X)=1 ; Var(X)=1)
 double nextGamma(double alpha, double beta)
          generates a random number from Gamma(alpha,beta) (E(X)=alpha*beta ; Var(X)=alpha*beta^2)
 double nextGamma(double alpha, double beta, double lambda)
          generates a random number from shifted-Gamma(alpha,beta) (E(X)=alpha*beta+lambda ; Var(X)=alpha*beta^2)
 double nextGammaLog(double alpha, double beta)
           
 double nextGaussian()
          generates a random number from N(0,1) (E(X)=0 ; Var(X)=1)
 double nextGaussian(double m, double s2)
          generates a random number from N(m,s2) (E(X)=m ; Var(X)=s2)
 int nextInt()
          generates an integer between 0 and 2^32
 int nextInt(int n)
          generates an integer between 0 and n-1 (inclusive)
 int nextPoisson()
          generates a random number from Poisson(1) (E(X)=1 ; Var(X)=1)
 int nextPoisson(double lambda)
          generates a random number from Poisson(lambda) (E(X)=lambda ; Var(X)=lambda)
 double nextUniform()
          generates a random number from U(0,1) (E(X)=1/2 ; Var(X)=1/12)
 double nextUniform(double a, double b)
          generates a random number from U(a,b) (E(X)=(b-a)/2 ; Var(X)=(b-a)^2/12)
protected  void setSeed(long seed)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomNumberGenerator

public RandomNumberGenerator()

RandomNumberGenerator

public RandomNumberGenerator(long seed)
Method Detail

setSeed

protected void setSeed(long seed)

next

protected int next(int bits)

nextInt

public int nextInt()
generates an integer between 0 and 2^32


nextInt

public int nextInt(int n)
generates an integer between 0 and n-1 (inclusive)


nextPoisson

public int nextPoisson(double lambda)
generates a random number from Poisson(lambda) (E(X)=lambda ; Var(X)=lambda)


nextPoisson

public int nextPoisson()
generates a random number from Poisson(1) (E(X)=1 ; Var(X)=1)


nextBoolean

public boolean nextBoolean()
generates a random boolean variable


nextBoolean

public boolean nextBoolean(double p)
generates true with probability p


nextUniform

public double nextUniform()
generates a random number from U(0,1) (E(X)=1/2 ; Var(X)=1/12)


nextUniform

public double nextUniform(double a,
                          double b)
generates a random number from U(a,b) (E(X)=(b-a)/2 ; Var(X)=(b-a)^2/12)


nextGaussian

public double nextGaussian()
generates a random number from N(0,1) (E(X)=0 ; Var(X)=1)


nextGaussian

public double nextGaussian(double m,
                           double s2)
generates a random number from N(m,s2) (E(X)=m ; Var(X)=s2)


nextGamma

public double nextGamma()
generates a random number from Gamma(1,1) (E(X)=1 ; Var(X)=1)


nextGamma

public double nextGamma(double alpha,
                        double beta)
generates a random number from Gamma(alpha,beta) (E(X)=alpha*beta ; Var(X)=alpha*beta^2)


nextGamma

public double nextGamma(double alpha,
                        double beta,
                        double lambda)
generates a random number from shifted-Gamma(alpha,beta) (E(X)=alpha*beta+lambda ; Var(X)=alpha*beta^2)


nextGammaLog

public double nextGammaLog(double alpha,
                           double beta)

nextExp

public double nextExp()
generates a random number from Exp(1) (E(X)=1 ; Var(X)=1)


nextExp

public double nextExp(double beta)
generates a random number from Exp(beta) (E(X)=beta ; Var(X)=beta^2)


nextExp

public double nextExp(double beta,
                      double lambda)
generates a random number from shifted-Exp(beta) (E(X)=beta+lambda ; Var(X)=beta^2)


nextChiSq

public double nextChiSq()
generates a random number from ChiSq(1) (E(X)=1 ; Var(X)=2)


nextChiSq

public double nextChiSq(int df)
generates a random number from ChiSq(df) (E(X)=df ; Var(X)=2*df)


nextChiSq

public double nextChiSq(int df,
                        double lambda)
generates a random number from shifted-ChiSq(df) (E(X)=df+lambda ; Var(X)=2*df)


nextBeta

public double nextBeta(double alpha,
                       double beta)
generates a random number from Beta(alpha,beta) (E(X)=a/(a+b) ; Var(X)=ab/[(a+b+1)(a+b)^2])