public class RandomVariable
extends java.lang.Object
The Mersenne Twister algorithm is used to generate the uniform random numbers used by all methods in this class. The Mersenne Twister method provides an efficient portable means of generating random numbers with a long period of 219937-1. This class uses an implementation of Mesenne Twister written by Luc Maisonobe.
Constructor and Description |
---|
RandomVariable() |
Modifier and Type | Method and Description |
---|---|
static double |
beta(double a,
double b)
Generate a random number from a beta random variable.
|
static boolean |
binomial(double p)
Generate a random boolean value from a binomial random variable.
|
static int |
binomialInteger(double p)
Generate a random integer value from a binomial random variable.
|
static double |
cauchy(double median,
double stddev)
Generate a random number from a Cauchy random variable.
|
static double |
chisquare(int df)
Generate a random number from a chisquare random variable.
|
static double |
dirac(double[] values,
double[] pValues)
Generate a random number from a discrete random variable.
|
static double |
exponential(double lambda)
Generate a random number from an exponential random variable.
|
static double |
gamma(double alpha,
double beta)
Generate a random number from a gamma distributed random variable.
|
static int |
geometric(double p)
Generate a random value from a geometric random variable.
|
static double |
logNormal(double mean,
double stddev)
Generate a random number from a lognormal random variable.
|
static int |
negativebinomial(int s,
double p)
Generate a random value from a negative binomial variable.
|
static double |
normal(double mean,
double stddev)
Generate a random number from a Gaussian (Normal) random variable.
|
static int |
poisson(double lambda)
Generate a random number from a poisson random variable.
|
static double |
rand()
Generate a uniformly distributed random number between 0 and 1.
|
static int |
randInt(int min,
int max)
Generate a random integer within a specific range.
|
static double |
triangular(double min,
double max)
Generate a random number from a symmetric triangular random variable.
|
static double |
triangular(double min,
double median,
double max)
Generate a random number from a non-symmetric triangular random variable.
|
static double |
uniform(double min,
double max)
Generate a random number from a uniform random variable.
|
static double |
weibull(double eta,
double beta)
Generate a random number from a Weibull random variable.
|
public static double rand()
To use a different base random number generator, all you need to do is override this method in a subclass.
public static int randInt(int min, int max)
min
- Minimum value for the random integer.max
- Maximum value for the random integer.public static double beta(double a, double b)
a
- First parameter of the Beta random variable.b
- Second parameter of the Beta random variable.public static boolean binomial(double p)
p
- Probability for binomial.public static int binomialInteger(double p)
p
- Probability for binomial.public static double cauchy(double median, double stddev)
median
- Median of the Weibull random variablestddev
- Second parameter of the Cauchy random variable.public static double chisquare(int df)
df
- Degrees of freedom of the chisquare random variable.We compute the random chisquare value as the sum of "df" random normal deviates squared.
public static double dirac(double[] values, double[] pValues)
values
- Discrete values.pValues
- Probability of each value.public static double exponential(double lambda)
lambda
- Parameter of the exponential random variable.The mean of the exponential distribution is 1/lambda and the variance is 1/lambda^2 .
public static double gamma(double alpha, double beta)
alpha
- First parameter of gamma distribution.beta
- Second parameter of gamma distribution.public static int geometric(double p)
p
- Probability for geometric random variable.public static double logNormal(double mean, double stddev)
mean
- Mean of the normal random variable.stddev
- Standard deviation of the normal random variable.public static int negativebinomial(int s, double p)
s
- p
- Probability for negative binomial random variable.public static double normal(double mean, double stddev)
mean
- Mean of the random variable.stddev
- Standard deviation of the random variable.public static int poisson(double lambda)
lambda
- Parameter of the exponential random variable.public static double triangular(double min, double max)
min
- Minimum value of the random variable.max
- Maximum value of the random variable.public static double triangular(double min, double median, double max)
min
- Minimum value of the random variable.median
- Value of the random variable which has maximum density.max
- Maximum value of the random variable.public static double uniform(double min, double max)
min
- Mininum value for the random variable.max
- Maximum value for the random variable.public static double weibull(double eta, double beta)
eta
- First parameter of the Weibull random variable.beta
- Second parameter of the Weibull random variable.