Package adams.data.random
Class Random
- java.lang.Object
-
- adams.data.random.Random
-
- All Implemented Interfaces:
Serializable
public class Random extends Object implements Serializable
Based on JMathArray's org.math.array.util.Random class. But in comparison to the original class, this one here is seedable and all methods are non-static.- Author:
- Yann RICHET (original JMathArray code), fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRandom.FunctionBased on JMathArray's org.math.array.util.Function.
-
Field Summary
Fields Modifier and Type Field Description protected RandomSeedablem_RandEnginethe random number generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublebeta(double a, double b)Generate a random number from a beta random variable.doublecauchy(double mu, double sigma)Generate a random number from a Cauchy random variable (Mean = Inf, and Variance = Inf).doublechi2(int n)Generate a random number from a Chi-2 random variable.doubledirac(double[] values, double[] prob)Generate a random number from a discrete random variable.doubleexponential(double lambda)Generate a random number from an exponantial random variable (Mean = 1/lambda, variance = 1/lambda^2).doublelogNormal(double mu, double sigma)Generate a random number from a LogNormal random variable.doublenormal(double mu, double sigma)Generate a random number from a Gaussian (Normal) random variable.intrandInt(int i0, int i1)Generate a random integer.doubleraw()Generate a random number between 0 and 1.doublerejection(Random.Function fun, double maxFun, double min, double max)Generate a random number from a random variable definied by its density function, using the rejection technic. !!!doubletriangular(double min, double max)Generate a random number from a symetric triangular random variable.doubletriangular(double min, double med, double max)Generate a random number from a non-symetric triangular random variable.doubleuniform(double min, double max)Generate a random number from a uniform random variable.doubleweibull(double lambda, double c)Generate a random number from a Weibull random variable.
-
-
-
Field Detail
-
m_RandEngine
protected RandomSeedable m_RandEngine
the random number generator.
-
-
Method Detail
-
raw
public double raw()
Generate a random number between 0 and 1. maybe changed for a better random number generator if needed.- Returns:
- A double between 0 and 1.
-
randInt
public int randInt(int i0, int i1)Generate a random integer.- Parameters:
i0- Min of the random variable.i1- Max of the random variable.- Returns:
- An int between i0 and i1.
-
uniform
public double uniform(double min, double max)Generate a random number from a uniform random variable.- Parameters:
min- Min of the random variable.max- Max of the random variable.- Returns:
- A double.
-
dirac
public double dirac(double[] values, double[] prob)Generate a random number from a discrete random variable.- Parameters:
values- Discrete values.prob- Probability of each value.- Returns:
- A double.
-
normal
public double normal(double mu, double sigma)Generate a random number from a Gaussian (Normal) random variable.- Parameters:
mu- Mean of the random variable.sigma- Standard deviation of the random variable.- Returns:
- A double.
-
chi2
public double chi2(int n)
Generate a random number from a Chi-2 random variable.- Parameters:
n- Degrees of freedom of the chi2 random variable.- Returns:
- A double.
-
logNormal
public double logNormal(double mu, double sigma)Generate a random number from a LogNormal random variable.- Parameters:
mu- Mean of the Normal random variable.sigma- Standard deviation of the Normal random variable.- Returns:
- A double.
-
exponential
public double exponential(double lambda)
Generate a random number from an exponantial random variable (Mean = 1/lambda, variance = 1/lambda^2).- Parameters:
lambda- Parmaeter of the exponential random variable.- Returns:
- A double.
-
triangular
public double triangular(double min, double max)Generate a random number from a symetric triangular random variable.- Parameters:
min- Min of the random variable.max- Max of the random variable.- Returns:
- A double.
-
triangular
public double triangular(double min, double med, double max)Generate a random number from a non-symetric triangular random variable.- Parameters:
min- Min of the random variable.med- Value of the random variable with max density.max- Max of the random variable.- Returns:
- A double.
-
beta
public double beta(double a, double b)Generate a random number from a beta random variable.- Parameters:
a- First parameter of the Beta random variable.b- Second parameter of the Beta random variable.- Returns:
- A double.
-
cauchy
public double cauchy(double mu, double sigma)Generate a random number from a Cauchy random variable (Mean = Inf, and Variance = Inf).- Parameters:
mu- Median of the Weibull random variablesigma- Second parameter of the Cauchy random variable.- Returns:
- A double.
-
weibull
public double weibull(double lambda, double c)Generate a random number from a Weibull random variable.- Parameters:
lambda- First parameter of the Weibull random variable.c- Second parameter of the Weibull random variable.- Returns:
- A double.
-
rejection
public double rejection(Random.Function fun, double maxFun, double min, double max)
Generate a random number from a random variable definied by its density function, using the rejection technic. !!! WARNING : this simulation technic can take a very long time !!!- Parameters:
fun- Density function (may be not normalized) of the random variable.maxFun- Max of the function.min- Min of the random variable.max- Max of the random variable.- Returns:
- A double.
-
-