Class JSLRandom
- java.lang.Object
-
- jsl.utilities.random.rvariable.JSLRandom
-
public class JSLRandom extends java.lang.Object
The purpose of this class is to facilitate random variate generation from various distributions through a set of static class methods.Each method marked rXXXX will generate random variates from the named distribution. The user has the option of supplying a RNStreamIfc as the source of the randomness. Methods that do not have a RNStreamIfc parameter use, getDefaultRNStream() as the source of randomness. That is, they all share the same stream, which is the default stream from the default random number stream factory. The user has the option of supplying a stream number to identify the stream from the underlying stream provider. By default, stream 1 is the default stream for the default provider. Stream 2 refers to the 2nd stream, etc.
Also provides a number of methods for sampling with and without replacement from arrays and lists as well as creating permutations of arrays and lists.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSLRandom.AlgoType
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double[]
copyFirstNValues(double[] x, int n)
Facilitates sampling without replacement to a new array.static java.util.stream.DoubleStream
createDoubleStream()
static RNStreamIfc
getDefaultRNStream()
static RNStreamProviderIfc
getRNStreamProvider()
static int
getStreamNumber(RNStreamIfc stream)
static boolean
isValidCDF(double[] cdf)
static boolean
isValidPMF(double[] prob)
Each element must be in (0,1) and sum of elements must be less than or equal to 1.0static double[]
makeCDF(double[] prob)
static RNStreamIfc
nextRNStream()
static void
permutation(boolean[] x)
Randomly permutes the supplied array using the default random number generator.static void
permutation(boolean[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.static void
permutation(boolean[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.static void
permutation(double[] x)
Randomly permutes the supplied array using the default random number generator.static void
permutation(double[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changedstatic void
permutation(double[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changedstatic void
permutation(int[] x)
Randomly permutes the supplied array using the default random number generator.static void
permutation(int[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.static void
permutation(int[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.static <T> void
permutation(java.util.List<T> x)
Randomly permutes the supplied List using the supplied random number generator, the list is changedstatic <T> void
permutation(java.util.List<T> x, int streamNum)
Randomly permutes the supplied List using the supplied random number generator, the list is changedstatic <T> void
permutation(java.util.List<T> x, RNStreamIfc rng)
Randomly permutes the supplied List using the supplied random number generator, the list is changedstatic <T> void
permutation(T[] x)
Randomly permutes the supplied array using the default random number generator.static <T> void
permutation(T[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changedstatic <T> void
permutation(T[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changedstatic double
randomlySelect(double[] array)
Randomly select an element from the arraystatic double
randomlySelect(double[] array, double[] cdf)
Randomly selects from the array using the supplied cdfstatic double
randomlySelect(double[] array, double[] cdf, int streamNum)
Randomly selects from the array using the supplied cdfstatic double
randomlySelect(double[] array, double[] cdf, RNStreamIfc rng)
Randomly selects from the array using the supplied cdfstatic double
randomlySelect(double[] array, int streamNum)
Randomly select an element from the arraystatic double
randomlySelect(double[] array, RNStreamIfc rng)
Randomly select an element from the arraystatic int
randomlySelect(int[] array)
Randomly select an element from the arraystatic int
randomlySelect(int[] array, double[] cdf)
Randomly selects from the array using the supplied cdfstatic int
randomlySelect(int[] array, double[] cdf, int streamNum)
Randomly selects from the array using the supplied cdfstatic int
randomlySelect(int[] array, double[] cdf, RNStreamIfc rng)
Randomly selects from the array using the supplied cdfstatic int
randomlySelect(int[] array, int streamNum)
Randomly select an element from the arraystatic int
randomlySelect(int[] array, RNStreamIfc rng)
Randomly select an element from the arraystatic <T> T
randomlySelect(java.util.List<T> list)
Randomly select from the list using the default streamstatic <T> T
randomlySelect(java.util.List<T> list, double[] cdf)
Randomly selects from the list using the supplied cdfstatic <T> T
randomlySelect(java.util.List<T> list, double[] cdf, int streamNum)
Randomly selects from the list using the supplied cdfstatic <T> T
randomlySelect(java.util.List<T> list, double[] cdf, RNStreamIfc rng)
Randomly selects from the list using the supplied cdfstatic <T> T
randomlySelect(java.util.List<T> list, int streamNum)
Randomly select from the liststatic <T> T
randomlySelect(java.util.List<T> list, RNStreamIfc rng)
Randomly select from the liststatic double
rBernoulli(double pSuccess)
static double
rBernoulli(double pSuccess, int streamNum)
static double
rBernoulli(double pSuccess, RNStreamIfc stream)
static double
rBeta(double alpha1, double alpha2)
This beta is restricted to the range of (0,1)static double
rBeta(double alpha1, double alpha2, int streamNum)
This beta is restricted to the range of (0,1)static double
rBeta(double alpha1, double alpha2, RNStreamIfc rng)
This beta is restricted to the range of (0,1)static double
rBetaG(double alpha1, double alpha2, double minimum, double maximum)
This beta is restricted to the range of (minimum,maximum)static double
rBetaG(double alpha1, double alpha2, double minimum, double maximum, int streamNum)
This beta is restricted to the range of (minimum,maximum)static double
rBetaG(double alpha1, double alpha2, double minimum, double maximum, RNStreamIfc rng)
This beta is restricted to the range of (minimum,maximum)static int
rBinomial(double pSuccess, int nTrials)
static int
rBinomial(double pSuccess, int nTrials, int streamNum)
static int
rBinomial(double pSuccess, int nTrials, RNStreamIfc stream)
static double
rChiSquared(double dof)
static double
rChiSquared(double dof, int streamNum)
static double
rChiSquared(double dof, RNStreamIfc rng)
static int
rDUniform(int minimum, int maximum)
Generates a discrete uniform over the rangestatic int
rDUniform(int minimum, int maximum, int streamNum)
Generates a discrete uniform over the rangestatic int
rDUniform(int minimum, int maximum, RNStreamIfc rng)
Generates a discrete uniform over the rangestatic double
rExponential(double mean)
static double
rExponential(double mean, int streamNum)
static double
rExponential(double mean, RNStreamIfc rng)
static double
rGamma(double shape, double scale)
static double
rGamma(double shape, double scale, int streamNum)
static double
rGamma(double shape, double scale, int streamNum, JSLRandom.AlgoType type)
static double
rGamma(double shape, double scale, RNStreamIfc rng)
static double
rGamma(double shape, double scale, RNStreamIfc rng, JSLRandom.AlgoType type)
static int
rGeometric(double pSuccess)
static int
rGeometric(double pSuccess, int streamNum)
static int
rGeometric(double pSuccess, RNStreamIfc rng)
static double
rJohnsonB(double alpha1, double alpha2, double min, double max)
static double
rJohnsonB(double alpha1, double alpha2, double min, double max, int streamNum)
static double
rJohnsonB(double alpha1, double alpha2, double min, double max, RNStreamIfc rng)
static double
rLaplace(double mean, double scale)
Generates according to a Laplace(mean, scale)static double
rLaplace(double mean, double scale, int streamNum)
Generates according to a Laplace(mean, scale)static double
rLaplace(double mean, double scale, RNStreamIfc rng)
Generates according to a Laplace(mean, scale)static double
rLogLogistic(double shape, double scale)
static double
rLogLogistic(double shape, double scale, int streamNum)
static double
rLogLogistic(double shape, double scale, RNStreamIfc rng)
static double
rLogNormal(double mean, double variance)
static double
rLogNormal(double mean, double variance, int streamNum)
static double
rLogNormal(double mean, double variance, RNStreamIfc rng)
static int
rNegBinomial(double pSuccess, double rSuccesses)
static int
rNegBinomial(double pSuccess, double rSuccesses, int streamNum)
static int
rNegBinomial(double pSuccess, double rSuccesses, RNStreamIfc rng)
static double
rNormal()
Generates a N(0,1) random value using the default streamstatic double
rNormal(double mean, double variance)
static double
rNormal(double mean, double variance, int streamNum)
static double
rNormal(double mean, double variance, RNStreamIfc rng)
static double
rNormal(int streamNum)
Generates a N(0,1) random value using the supplied stream numberstatic double
rNormal(RNStreamIfc rng)
Generates a N(0,1) random value using the supplied streamstatic RNStreamIfc
rnStream(int streamNum)
static double
rPearsonType5(double shape, double scale)
static double
rPearsonType5(double shape, double scale, int streamNum)
static double
rPearsonType5(double shape, double scale, RNStreamIfc rng)
static double
rPearsonType6(double alpha1, double alpha2, double beta)
Pearson Type 6static double
rPearsonType6(double alpha1, double alpha2, double beta, int streamNum)
Pearson Type 6static double
rPearsonType6(double alpha1, double alpha2, double beta, RNStreamIfc rng)
Pearson Type 6static int
rPoisson(double mean)
static int
rPoisson(double mean, int streamNum)
static int
rPoisson(double mean, RNStreamIfc rng)
static double
rTriangular(double min, double mode, double max)
static double
rTriangular(double min, double mode, double max, int streamNum)
static double
rTriangular(double min, double mode, double max, RNStreamIfc rng)
static double
rUniform()
Generates a continuous U(0,1) using the default streamstatic double
rUniform(double minimum, double maximum)
Generates a continuous uniform over the rangestatic double
rUniform(double minimum, double maximum, int streamNum)
Generates a continuous uniform over the rangestatic double
rUniform(double minimum, double maximum, RNStreamIfc rng)
Generates a continuous uniform over the rangestatic double
rUniform(int streamNum)
Generates a continuous U(0,1) using the supplied stream numberstatic double
rUniform(RNStreamIfc rnStream)
Generates a continuous U(0,1) using the supplied streamstatic double
rWeibull(double shape, double scale)
static double
rWeibull(double shape, double scale, int streamNum)
static double
rWeibull(double shape, double scale, RNStreamIfc rng)
static void
sampleWithoutReplacement(boolean[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the generated sample.static void
sampleWithoutReplacement(boolean[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the generated sample.static void
sampleWithoutReplacement(boolean[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the generated sample.static void
sampleWithoutReplacement(double[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the sample.static void
sampleWithoutReplacement(double[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the sample.static void
sampleWithoutReplacement(double[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the sample.static void
sampleWithoutReplacement(int[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the generated sample.static void
sampleWithoutReplacement(int[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the generated sample.static void
sampleWithoutReplacement(int[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the generated sample.static <T> void
sampleWithoutReplacement(java.util.List<T> x, int sampleSize)
The List x is changed, such that the first sampleSize elements contain the generate.static <T> void
sampleWithoutReplacement(java.util.List<T> x, int sampleSize, int streamNum)
The List x is changed, such that the first sampleSize elements contain the generate.static <T> void
sampleWithoutReplacement(java.util.List<T> x, int sampleSize, RNStreamIfc rng)
The List x is changed, such that the first sampleSize elements contain the generate.static <T> void
sampleWithoutReplacement(T[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the generated sample.static <T> void
sampleWithoutReplacement(T[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the generated sample.static <T> void
sampleWithoutReplacement(T[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the generated sample.static void
setRNStreamProvider(RNStreamProviderIfc streamProvider)
Sets the underlying stream provider for all JSLRandom method usage
-
-
-
Method Detail
-
setRNStreamProvider
public static void setRNStreamProvider(RNStreamProviderIfc streamProvider)
Sets the underlying stream provider for all JSLRandom method usage- Parameters:
streamProvider
- an instance of a stream provider
-
getRNStreamProvider
public static RNStreamProviderIfc getRNStreamProvider()
- Returns:
- the provider that is currently being used for all JSLRandom method calls
-
nextRNStream
public static RNStreamIfc nextRNStream()
- Returns:
- gets the next stream of pseudo random numbers from the default random number stream provider
-
getStreamNumber
public static int getStreamNumber(RNStreamIfc stream)
- Parameters:
stream
- the stream associated with the default stream provider- Returns:
- the number associated with the provided stream or -1 if the stream was not provided by the default provider
-
rnStream
public static RNStreamIfc rnStream(int streamNum)
- Parameters:
streamNum
- the stream number associated with the stream- Returns:
- the stream associated with the stream number from the underlying stream provider
-
getDefaultRNStream
public static RNStreamIfc getDefaultRNStream()
- Returns:
- the default stream from the default random number stream provider
-
createDoubleStream
public static java.util.stream.DoubleStream createDoubleStream()
- Returns:
- returns a new stream from the default stream factory using the Stream API
-
rBernoulli
public static double rBernoulli(double pSuccess)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)- Returns:
- the random value
-
rBernoulli
public static double rBernoulli(double pSuccess, int streamNum)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rBernoulli
public static double rBernoulli(double pSuccess, RNStreamIfc stream)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)stream
- the RNStreamIfc- Returns:
- the random value
-
rBinomial
public static int rBinomial(double pSuccess, int nTrials)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)nTrials
- the number of trials, must be greater than 0- Returns:
- the random value
-
rBinomial
public static int rBinomial(double pSuccess, int nTrials, int streamNum)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)nTrials
- the number of trials, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rBinomial
public static int rBinomial(double pSuccess, int nTrials, RNStreamIfc stream)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)nTrials
- the number of trials, must be greater than 0stream
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rPoisson
public static int rPoisson(double mean)
- Parameters:
mean
- the mean of the Poisson, must be greater than 0- Returns:
- the random value
-
rPoisson
public static int rPoisson(double mean, int streamNum)
- Parameters:
mean
- the mean of the Poisson, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rPoisson
public static int rPoisson(double mean, RNStreamIfc rng)
- Parameters:
mean
- the mean of the Poisson, must be greater than 0rng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rDUniform
public static int rDUniform(int minimum, int maximum)
Generates a discrete uniform over the range- Parameters:
minimum
- the minimum of the rangemaximum
- the maximum of the range- Returns:
- the random value
-
rDUniform
public static int rDUniform(int minimum, int maximum, int streamNum)
Generates a discrete uniform over the range- Parameters:
minimum
- the minimum of the rangemaximum
- the maximum of the rangestreamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rDUniform
public static int rDUniform(int minimum, int maximum, RNStreamIfc rng)
Generates a discrete uniform over the range- Parameters:
minimum
- the minimum of the rangemaximum
- the maximum of the rangerng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rGeometric
public static int rGeometric(double pSuccess)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)- Returns:
- the random value
-
rGeometric
public static int rGeometric(double pSuccess, int streamNum)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rGeometric
public static int rGeometric(double pSuccess, RNStreamIfc rng)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)rng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rNegBinomial
public static int rNegBinomial(double pSuccess, double rSuccesses)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)rSuccesses
- number of trials until rth success, must be greater than 0- Returns:
- the random value
-
rNegBinomial
public static int rNegBinomial(double pSuccess, double rSuccesses, int streamNum)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)rSuccesses
- number of trials until rth successstreamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rNegBinomial
public static int rNegBinomial(double pSuccess, double rSuccesses, RNStreamIfc rng)
- Parameters:
pSuccess
- the probability of success, must be in (0,1)rSuccesses
- number of trials until rth successrng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rUniform
public static double rUniform()
Generates a continuous U(0,1) using the default stream- Returns:
- the random value
-
rUniform
public static double rUniform(int streamNum)
Generates a continuous U(0,1) using the supplied stream number- Parameters:
streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rUniform
public static double rUniform(RNStreamIfc rnStream)
Generates a continuous U(0,1) using the supplied stream- Parameters:
rnStream
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rUniform
public static double rUniform(double minimum, double maximum)
Generates a continuous uniform over the range- Parameters:
minimum
- the minimum of the range, must be less than maximummaximum
- the maximum of the range- Returns:
- the random value
-
rUniform
public static double rUniform(double minimum, double maximum, int streamNum)
Generates a continuous uniform over the range- Parameters:
minimum
- the minimum of the range, must be less than maximummaximum
- the maximum of the rangestreamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rUniform
public static double rUniform(double minimum, double maximum, RNStreamIfc rng)
Generates a continuous uniform over the range- Parameters:
minimum
- the minimum of the range, must be less than maximummaximum
- the maximum of the rangerng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rNormal
public static double rNormal()
Generates a N(0,1) random value using the default stream- Returns:
- the random value
-
rNormal
public static double rNormal(int streamNum)
Generates a N(0,1) random value using the supplied stream number- Parameters:
streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rNormal
public static double rNormal(RNStreamIfc rng)
Generates a N(0,1) random value using the supplied stream- Parameters:
rng
- the RNStreamIfc, must not null- Returns:
- the random value
-
rNormal
public static double rNormal(double mean, double variance)
- Parameters:
mean
- the mean of the normalvariance
- the variance of the normal, must be greater than 0- Returns:
- the random value
-
rNormal
public static double rNormal(double mean, double variance, int streamNum)
- Parameters:
mean
- the mean of the normalvariance
- the variance of the normal, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rNormal
public static double rNormal(double mean, double variance, RNStreamIfc rng)
- Parameters:
mean
- the mean of the normalvariance
- the variance of the normal, must be greater than 0rng
- the RNStreamIfc, must not null- Returns:
- the random value
-
rLogNormal
public static double rLogNormal(double mean, double variance)
- Parameters:
mean
- the mean of the lognormal, must be greater than 0variance
- the variance of the lognormal, must be greater than 0- Returns:
- the random value
-
rLogNormal
public static double rLogNormal(double mean, double variance, int streamNum)
- Parameters:
mean
- the mean of the lognormal, must be greater than 0variance
- the variance of the lognormal, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rLogNormal
public static double rLogNormal(double mean, double variance, RNStreamIfc rng)
- Parameters:
mean
- the mean of the lognormal, must be greater than 0variance
- the variance of the lognormal, must be greater than 0rng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rWeibull
public static double rWeibull(double shape, double scale)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0- Returns:
- the random value
-
rWeibull
public static double rWeibull(double shape, double scale, int streamNum)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rWeibull
public static double rWeibull(double shape, double scale, RNStreamIfc rng)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0rng
- the RNStreamIfc, must not null- Returns:
- the random value
-
rExponential
public static double rExponential(double mean)
- Parameters:
mean
- the mean, must be greater than 0- Returns:
- the random value
-
rExponential
public static double rExponential(double mean, int streamNum)
- Parameters:
mean
- the mean, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rExponential
public static double rExponential(double mean, RNStreamIfc rng)
- Parameters:
mean
- the mean, must be greater than 0rng
- the RNStreamIfc, must not null- Returns:
- the random value
-
rJohnsonB
public static double rJohnsonB(double alpha1, double alpha2, double min, double max)
- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parametermin
- the minmax
- the max- Returns:
- the generated value
-
rJohnsonB
public static double rJohnsonB(double alpha1, double alpha2, double min, double max, int streamNum)
- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameter, must be greater than zeromin
- the min, must be less than maxmax
- the maxstreamNum
- the stream number from the stream provider to use- Returns:
- the generated value
-
rJohnsonB
public static double rJohnsonB(double alpha1, double alpha2, double min, double max, RNStreamIfc rng)
- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameter, must be greater than zeromin
- the min, must be less than maxmax
- the maxrng
- the RNStreamIfc, must not be null- Returns:
- the generated value
-
rLogLogistic
public static double rLogLogistic(double shape, double scale)
- Parameters:
shape
- the shapescale
- the scale- Returns:
- the generated value
-
rLogLogistic
public static double rLogLogistic(double shape, double scale, int streamNum)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the generated value
-
rLogLogistic
public static double rLogLogistic(double shape, double scale, RNStreamIfc rng)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0rng
- the RNStreamIfc, must not be null- Returns:
- the generated value
-
rTriangular
public static double rTriangular(double min, double mode, double max)
- Parameters:
min
- the min, must be less than or equal to modemode
- the mode, must be less than or equal to maxmax
- the max- Returns:
- the random value
-
rTriangular
public static double rTriangular(double min, double mode, double max, int streamNum)
- Parameters:
min
- the min, must be less than or equal to modemode
- the mode, must be less than or equal to maxmax
- the maxstreamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rTriangular
public static double rTriangular(double min, double mode, double max, RNStreamIfc rng)
- Parameters:
min
- the min, must be less than or equal to modemode
- the mode, must be less than or equal to maxmax
- the maxrng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rGamma
public static double rGamma(double shape, double scale)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0- Returns:
- the generated value
-
rGamma
public static double rGamma(double shape, double scale, RNStreamIfc rng)
- Parameters:
shape
- the shape, must be greater than 0.0scale
- the scale, must be greater than 0.0rng
- the RNStreamIfc, must not null- Returns:
- the generated value
-
rGamma
public static double rGamma(double shape, double scale, int streamNum)
- Parameters:
shape
- the shape, must be greater than 0.0scale
- the scale, must be greater than 0.0streamNum
- the stream number from the stream provider to use- Returns:
- the generated value
-
rGamma
public static double rGamma(double shape, double scale, int streamNum, JSLRandom.AlgoType type)
- Parameters:
shape
- the shape, must be greater than 0.0scale
- the scale, must be greater than 0.0streamNum
- the stream number from the stream provider to usetype
- , must be appropriate algorithm type, if null then inverse transform is the default- Returns:
- the generated value
-
rGamma
public static double rGamma(double shape, double scale, RNStreamIfc rng, JSLRandom.AlgoType type)
- Parameters:
shape
- the shape, must be greater than 0.0scale
- the scale, must be greater than 0.0rng
- the RNStreamIfc, must not nulltype
- , must be appropriate algorithm type, if null then inverse transform is the default- Returns:
- the generated value
-
rChiSquared
public static double rChiSquared(double dof)
- Parameters:
dof
- degrees of freedom, must be greater than 0- Returns:
- the random value
-
rChiSquared
public static double rChiSquared(double dof, int streamNum)
- Parameters:
dof
- degrees of freedom, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rChiSquared
public static double rChiSquared(double dof, RNStreamIfc rng)
- Parameters:
dof
- degrees of freedom, must be greater than 0rng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rPearsonType5
public static double rPearsonType5(double shape, double scale)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0- Returns:
- the generated value
-
rPearsonType5
public static double rPearsonType5(double shape, double scale, int streamNum)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the generated value
-
rPearsonType5
public static double rPearsonType5(double shape, double scale, RNStreamIfc rng)
- Parameters:
shape
- the shape, must be greater than 0scale
- the scale, must be greater than 0rng
- the RNStreamIfc, must not be null- Returns:
- the generated value
-
rBeta
public static double rBeta(double alpha1, double alpha2)
This beta is restricted to the range of (0,1)- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameter- Returns:
- the random value
-
rBeta
public static double rBeta(double alpha1, double alpha2, int streamNum)
This beta is restricted to the range of (0,1)- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterstreamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rBeta
public static double rBeta(double alpha1, double alpha2, RNStreamIfc rng)
This beta is restricted to the range of (0,1)- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterrng
- the RNStreamIfc- Returns:
- the random value
-
rBetaG
public static double rBetaG(double alpha1, double alpha2, double minimum, double maximum)
This beta is restricted to the range of (minimum,maximum)- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterminimum
- the minimum of the rangemaximum
- the maximum of the range- Returns:
- the random value
-
rBetaG
public static double rBetaG(double alpha1, double alpha2, double minimum, double maximum, int streamNum)
This beta is restricted to the range of (minimum,maximum)- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterminimum
- the minimum of the range, must be less than maximummaximum
- the maximum of the rangestreamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rBetaG
public static double rBetaG(double alpha1, double alpha2, double minimum, double maximum, RNStreamIfc rng)
This beta is restricted to the range of (minimum,maximum)- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterminimum
- the minimum of the range, must be less than maximummaximum
- the maximum of the rangerng
- the RNStreamIfc- Returns:
- the random value
-
rPearsonType6
public static double rPearsonType6(double alpha1, double alpha2, double beta)
Pearson Type 6- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterbeta
- the beta parameter- Returns:
- the random value
-
rPearsonType6
public static double rPearsonType6(double alpha1, double alpha2, double beta, int streamNum)
Pearson Type 6- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterbeta
- the beta parameter, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rPearsonType6
public static double rPearsonType6(double alpha1, double alpha2, double beta, RNStreamIfc rng)
Pearson Type 6- Parameters:
alpha1
- alpha1 parameteralpha2
- alpha2 parameterbeta
- the beta parameter, must be greater than 0rng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
rLaplace
public static double rLaplace(double mean, double scale)
Generates according to a Laplace(mean, scale)- Parameters:
mean
- mean or location parameterscale
- scale parameter, must be greater than 0- Returns:
- the random value
-
rLaplace
public static double rLaplace(double mean, double scale, int streamNum)
Generates according to a Laplace(mean, scale)- Parameters:
mean
- mean or location parameterscale
- scale parameter, must be greater than 0streamNum
- the stream number from the stream provider to use- Returns:
- the random value
-
rLaplace
public static double rLaplace(double mean, double scale, RNStreamIfc rng)
Generates according to a Laplace(mean, scale)- Parameters:
mean
- mean or location parameterscale
- scale parameter, must be greater than 0rng
- the RNStreamIfc, must not be null- Returns:
- the random value
-
randomlySelect
public static int randomlySelect(int[] array)
Randomly select an element from the array- Parameters:
array
- the array to select from- Returns:
- the randomly selected value
-
randomlySelect
public static int randomlySelect(int[] array, int streamNum)
Randomly select an element from the array- Parameters:
array
- the array to select fromstreamNum
- the stream number from the stream provider to use- Returns:
- the randomly selected value
-
randomlySelect
public static int randomlySelect(int[] array, RNStreamIfc rng)
Randomly select an element from the array- Parameters:
array
- the array to select fromrng
- the source of randomness- Returns:
- the randomly selected value
-
randomlySelect
public static double randomlySelect(double[] array)
Randomly select an element from the array- Parameters:
array
- the array to select from- Returns:
- the randomly selected value
-
randomlySelect
public static double randomlySelect(double[] array, int streamNum)
Randomly select an element from the array- Parameters:
array
- the array to select fromstreamNum
- the stream number from the stream provider to use- Returns:
- the randomly selected value
-
randomlySelect
public static double randomlySelect(double[] array, RNStreamIfc rng)
Randomly select an element from the array- Parameters:
array
- the array to select fromrng
- the source of randomness- Returns:
- the randomly selected value
-
randomlySelect
public static double randomlySelect(double[] array, double[] cdf)
Randomly selects from the array using the supplied cdf- Parameters:
array
- array to select fromcdf
- the cumulative probability associated with each element of array- Returns:
- the randomly selected value
-
randomlySelect
public static double randomlySelect(double[] array, double[] cdf, int streamNum)
Randomly selects from the array using the supplied cdf- Parameters:
array
- array to select fromcdf
- the cumulative probability associated with each element of arraystreamNum
- the stream number from the stream provider to use- Returns:
- the randomly selected value
-
randomlySelect
public static double randomlySelect(double[] array, double[] cdf, RNStreamIfc rng)
Randomly selects from the array using the supplied cdf- Parameters:
array
- array to select fromcdf
- the cumulative probability associated with each element of arrayrng
- the source of randomness- Returns:
- the randomly selected value
-
randomlySelect
public static int randomlySelect(int[] array, double[] cdf)
Randomly selects from the array using the supplied cdf- Parameters:
array
- array to select fromcdf
- the cumulative probability associated with each element of array- Returns:
- the randomly selected value
-
randomlySelect
public static int randomlySelect(int[] array, double[] cdf, int streamNum)
Randomly selects from the array using the supplied cdf- Parameters:
array
- array to select fromcdf
- the cumulative probability associated with each element of arraystreamNum
- the stream number from the stream provider to use- Returns:
- the randomly selected value
-
randomlySelect
public static int randomlySelect(int[] array, double[] cdf, RNStreamIfc rng)
Randomly selects from the array using the supplied cdf- Parameters:
array
- array to select fromcdf
- the cumulative probability associated with each element of arrayrng
- the source of randomness- Returns:
- the randomly selected value
-
randomlySelect
public static <T> T randomlySelect(java.util.List<T> list, double[] cdf)
Randomly selects from the list using the supplied cdf- Type Parameters:
T
- the type returned- Parameters:
list
- list to select fromcdf
- the cumulative probability associated with each element of array- Returns:
- the randomly selected value
-
randomlySelect
public static <T> T randomlySelect(java.util.List<T> list, double[] cdf, int streamNum)
Randomly selects from the list using the supplied cdf- Type Parameters:
T
- the type returned- Parameters:
list
- list to select fromcdf
- the cumulative probability associated with each element of arraystreamNum
- the stream number from the stream provider to use- Returns:
- the randomly selected value
-
randomlySelect
public static <T> T randomlySelect(java.util.List<T> list, double[] cdf, RNStreamIfc rng)
Randomly selects from the list using the supplied cdf- Type Parameters:
T
- the type returned- Parameters:
list
- list to select fromcdf
- the cumulative probability associated with each element of arrayrng
- the source of randomness- Returns:
- the randomly selected value
-
isValidCDF
public static boolean isValidCDF(double[] cdf)
- Parameters:
cdf
- the probability array. must have valid probability elements and last element equal to 1. Every element must be greater than or equal to the previous element. That is, monotonically increasing.- Returns:
- true if valid cdf
-
isValidPMF
public static boolean isValidPMF(double[] prob)
Each element must be in (0,1) and sum of elements must be less than or equal to 1.0- Parameters:
prob
- the array to check, must not be null, must have at least two elements- Returns:
- true if the array represents a probability mass function
-
makeCDF
public static double[] makeCDF(double[] prob)
- Parameters:
prob
- the array representing a PMF- Returns:
- a valid CDF
-
randomlySelect
public static <T> T randomlySelect(java.util.List<T> list)
Randomly select from the list using the default stream- Type Parameters:
T
- The type of element in the list- Parameters:
list
- the list- Returns:
- the randomly selected element
-
randomlySelect
public static <T> T randomlySelect(java.util.List<T> list, int streamNum)
Randomly select from the list- Type Parameters:
T
- The type of element in the list- Parameters:
list
- the liststreamNum
- the stream number from the stream provider to use- Returns:
- the randomly selected element
-
randomlySelect
public static <T> T randomlySelect(java.util.List<T> list, RNStreamIfc rng)
Randomly select from the list- Type Parameters:
T
- The type of element in the list- Parameters:
list
- the listrng
- the source of randomness- Returns:
- the randomly selected element
-
permutation
public static void permutation(double[] x)
Randomly permutes the supplied array using the default random number generator. The array is changed.- Parameters:
x
- the array
-
permutation
public static void permutation(double[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changed- Parameters:
x
- the arraystreamNum
- the stream number from the stream provider to use
-
permutation
public static void permutation(double[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changed- Parameters:
x
- the arrayrng
- the source of randomness
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(double[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement using the default random number generator- Parameters:
x
- the arraysampleSize
- the size of the generate
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(double[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement- Parameters:
x
- the arraysampleSize
- the generate sizestreamNum
- the stream number from the stream provider to use
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(double[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement- Parameters:
x
- the arraysampleSize
- the generate sizerng
- the source of randomness
-
copyFirstNValues
public static double[] copyFirstNValues(double[] x, int n)
Facilitates sampling without replacement to a new array. Example usage:sampleWithoutReplacement(x, 5); // first sample into first 5 slots double[] sample = copyFirstNValues(x, 5); // now copy from the first 5 slots
- Parameters:
x
- the array to copy fromn
- the number of values to copy- Returns:
- a new array with the values
-
permutation
public static void permutation(int[] x)
Randomly permutes the supplied array using the default random number generator. The array is changed.- Parameters:
x
- the array
-
permutation
public static void permutation(int[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.- Parameters:
x
- the arraystreamNum
- the stream number from the stream provider to use
-
permutation
public static void permutation(int[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.- Parameters:
x
- the arrayrng
- the source of randomness
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(int[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement using the default random number generator- Parameters:
x
- the arraysampleSize
- the generate size
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(int[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement- Parameters:
x
- the arraysampleSize
- the generate sizestreamNum
- the stream number from the stream provider to use
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(int[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement- Parameters:
x
- the arraysampleSize
- the generate sizerng
- the source of randomness
-
permutation
public static void permutation(boolean[] x)
Randomly permutes the supplied array using the default random number generator. The array is changed.- Parameters:
x
- the array
-
permutation
public static void permutation(boolean[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.- Parameters:
x
- the arraystreamNum
- the stream number from the stream provider to use
-
permutation
public static void permutation(boolean[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changed.- Parameters:
x
- the arrayrng
- the source of randomness
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(boolean[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement using the default random number generator- Parameters:
x
- the arraysampleSize
- the generate size
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(boolean[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement- Parameters:
x
- the arraysampleSize
- the generate sizestreamNum
- the stream number from the stream provider to use
-
sampleWithoutReplacement
public static void sampleWithoutReplacement(boolean[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement- Parameters:
x
- the arraysampleSize
- the generate sizerng
- the source of randomness
-
permutation
public static <T> void permutation(T[] x)
Randomly permutes the supplied array using the default random number generator. The array is changed- Parameters:
x
- the array
-
permutation
public static <T> void permutation(T[] x, int streamNum)
Randomly permutes the supplied array using the supplied random number generator, the array is changed- Parameters:
x
- the arraystreamNum
- the stream number from the stream provider to use
-
permutation
public static <T> void permutation(T[] x, RNStreamIfc rng)
Randomly permutes the supplied array using the supplied random number generator, the array is changed- Parameters:
x
- the arrayrng
- the source of randomness
-
sampleWithoutReplacement
public static <T> void sampleWithoutReplacement(T[] x, int sampleSize)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the randomly sampled values without replacement using the default random number generator- Parameters:
x
- the arraysampleSize
- the source of randomness
-
sampleWithoutReplacement
public static <T> void sampleWithoutReplacement(T[] x, int sampleSize, int streamNum)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the randomly sampled values without replacement- Parameters:
x
- the arraysampleSize
- the generate sizestreamNum
- the stream number from the stream provider to use
-
sampleWithoutReplacement
public static <T> void sampleWithoutReplacement(T[] x, int sampleSize, RNStreamIfc rng)
The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the randomly sampled values without replacement- Parameters:
x
- the arraysampleSize
- the generate sizerng
- the source of randomness
-
permutation
public static <T> void permutation(java.util.List<T> x)
Randomly permutes the supplied List using the supplied random number generator, the list is changed- Type Parameters:
T
- the type of the list- Parameters:
x
- the list
-
permutation
public static <T> void permutation(java.util.List<T> x, int streamNum)
Randomly permutes the supplied List using the supplied random number generator, the list is changed- Type Parameters:
T
- the type of the list- Parameters:
x
- the liststreamNum
- the stream number from the stream provider to use
-
permutation
public static <T> void permutation(java.util.List<T> x, RNStreamIfc rng)
Randomly permutes the supplied List using the supplied random number generator, the list is changed- Type Parameters:
T
- the type of the list- Parameters:
x
- the listrng
- the source of randomness
-
sampleWithoutReplacement
public static <T> void sampleWithoutReplacement(java.util.List<T> x, int sampleSize)
The List x is changed, such that the first sampleSize elements contain the generate. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement using the default random number generator- Type Parameters:
T
- the type of the list- Parameters:
x
- the listsampleSize
- the generate size
-
sampleWithoutReplacement
public static <T> void sampleWithoutReplacement(java.util.List<T> x, int sampleSize, int streamNum)
The List x is changed, such that the first sampleSize elements contain the generate. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement- Type Parameters:
T
- the type of the list- Parameters:
x
- the listsampleSize
- the generate sizestreamNum
- the stream number from the stream provider to use
-
sampleWithoutReplacement
public static <T> void sampleWithoutReplacement(java.util.List<T> x, int sampleSize, RNStreamIfc rng)
The List x is changed, such that the first sampleSize elements contain the generate. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement- Type Parameters:
T
- the type of the list- Parameters:
x
- the listsampleSize
- the generate sizerng
- the source of randomness
-
-