AnyLogic
Expand
Font size
All Known Implementing Classes:
Agent, Experiment, ExperimentCompareRuns, ExperimentMultipleRuns, ExperimentOptimization, ExperimentParamVariation, ExperimentRunFast, ExperimentSimulation, FlowchartBlock, Utilities

public interface UtilitiesRandom
Random number generation utilities for various probability distributions
Author:
AnyLogic North America, LLC https://anylogic.com

Field Summary

Modifier and TypeFieldDescription
static final intRANDOM_BOUNDED_DISTRIBUTIONS_MAX_ITERATIONS 

Method Summary

Modifier and TypeMethodDescription
default intbernoulli(double p)
Generates a sample of the Bernoulli distribution, i.e.
static intbernoulli(double p, Random r)
Generates a sample of the Bernoulli distribution using the specified random number generator.
default doublebeta(double p, double q)
Generates a sample of the Beta distribution with min set to 0 and max set to 1.
default doublebeta(double p, double q, double min, double max)
Generates a sample of the Beta distribution.
default doublebeta(double min, double max, double p, double q, double shift, double stretch)
Generates a sample of truncated Beta distribution.
Distribution beta(p, q, 0, 1) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublebeta(double min, double max, double p, double q, double shift, double stretch, Random r)
Generates a sample of truncated Beta distribution using the specified random number generator.
Distribution beta(p, q, 0, 1) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublebeta(double p, double q, double min, double max, Random r)
Generates a sample of the Beta distribution using the specified random number generator.
default intbinomial(double p)
Generates a sample of the Binomial distribution with n set to 1.
default doublebinomial(double min, double max, double p, double n, double shift, double stretch)
Generates a sample of truncated Binomial distribution.
Distribution binomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublebinomial(double min, double max, double p, double n, double shift, double stretch, Random r)
Generates a sample of truncated Binomial distribution using the specified random number generator.
Distribution binomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
default intbinomial(double p, int n)
Generates a sample of the Binomial distribution.
static intbinomial(double p, int n, Random r)
Generates a sample of the Binomial distribution using the specified random number generator.
default doublecauchy(double lambda)
Generates a sample of the Cauchy distribution with theta set to 0.
default doublecauchy(double lambda, double theta)
Generates a sample of the Cauchy distribution.
static doublecauchy(double lambda, double theta, Random r)
Generates a sample of the Cauchy distribution using the specified random number generator.
default doublechi2(double nu)
Generates a sample of the Chi Squared distribution with min set to 0.
default doublechi2(double nu, double min)
Generates a sample of the Chi Squared distribution.
static doublechi2(double nu, double min, Random r)
Generates a sample of the Chi Squared distribution using the specified random number generator.
default doubleerlang(double beta, int m)
Generates a sample of the Erlang distribution with min set to 0.
default doubleerlang(double beta, int m, double min)
Generates a sample of the Erlang distribution.
static doubleerlang(double beta, int m, double min, Random r)
Generates a sample of the Erlang distribution using the specified random number generator.
default doubleexponential()
Generates a sample of the Exponential distribution with lambda set to 1 and min set to 0.
default doubleexponential(double lambda)
Generates a sample of the Exponential distribution with min set to 0.
default doubleexponential(double lambda, double min)
Generates a sample of the Exponential distribution.
default doubleexponential(double min, double max, double shift, double stretch)
Generates a sample of truncated Exponential distribution.
Distribution exponential(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doubleexponential(double min, double max, double shift, double stretch, Random r)
Generates a sample of truncated Exponential distribution using the specified random number generator.
Distribution exponential(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doubleexponential(double lambda, double min, Random r)
Generates a sample of the Exponential distribution using the specified random number generator.
default doublegamma(double alpha, double beta)
Generates a sample of the Gamma distribution with min set to 0.
default doublegamma(double alpha, double beta, double min)
Generates a sample of the Gamma distribution.
default doublegamma(double min, double max, double alpha, double shift, double stretch)
Generates a sample of truncated Gamma distribution.
Distribution gamma(alpha, 1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublegamma(double min, double max, double alpha, double shift, double stretch, Random r)
Generates a sample of truncated Gamma distribution using the specified random number generator.
Distribution gamma(alpha, 1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublegamma(double alpha, double beta, double min, Random r)
Generates a sample of the Gamma distribution using the specified random number generator.
default intgeometric(double p)
Generates a sample of the Geometric distribution.
static intgeometric(double p, Random r)
Generates a sample of the Geometric distribution using the specified random number generator.
RandomgetDefaultRandomGenerator()
Retrieves the random number generator used by all probability distributions by default, i.e.
default doublegumbel1(double a, double b)
Generates a sample of the Type I Gumbel distribution.
This distribution has the form
p(x) = a b exp(-(b exp(-ax) + ax))
static doublegumbel1(double a, double b, Random r)
Generates a sample of the Type I Gumbel distribution using the specified random number generator.
default doublegumbel2(double a, double b)
Generates a sample of the Type II Gumbel distribution.
This distribution has the form
p(x) = b a x^-(a+1) exp(-b x^-a))
static doublegumbel2(double a, double b, Random r)
Generates a sample of the Type II Gumbel distribution using the specified random number generator.
default inthypergeometric(int ss, int dn, int ps)
Generates a sample of the Hypergeometric distribution.
static inthypergeometric(int ss, int dn, int ps, Random r)
Generates a sample of the Hypergeometric distribution using the specified random number generator.
default doublelaplace(double phi, double theta)
Generates a sample of the Laplace distribution.
static doublelaplace(double phi, double theta, Random r)
Generates a sample of the Laplace distribution using the specified random number generator.
default intlogarithmic(double theta)
Generates a sample of the Logarithmic distribution.
static intlogarithmic(double theta, Random r)
Generates a sample of the Logarithmic distribution using the specified random number generator.
default doublelogistic(double beta, double alpha)
Generates a sample of the Logistic distribution.
static doublelogistic(double beta, double alpha, Random r)
Generates a sample of the Logistic distribution using the specified random number generator.
default doublelognormal(double mu, double sigma, double min)
Generates a sample of the Lognormal distribution.
static doublelognormal(double mu, double sigma, double min, Random r)
Generates a sample of the Lognormal distribution using the specified random number generator.
default intnegativeBinomial(double p, double n)
Generates a sample of the Negative Binomial distribution.
default doublenegativeBinomial(double min, double max, double p, double n, double shift, double stretch)
Generates a sample of truncated Negative Binomial distribution.
Distribution negativeBinomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublenegativeBinomial(double min, double max, double p, double n, double shift, double stretch, Random r)
Generates a sample of truncated Negative Binomial distribution using the specified random number generator.
Distribution negativeBinomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static intnegativeBinomial(double p, double n, Random r)
Generates a sample of the Negative Binomial distribution using the specified random number generator.
default doublenormal()
Generates a sample of the Normal distribution with mean set to 0 and sigma set to 1.
default doublenormal(double sigma)
Generates a sample of the Normal distribution with mean set to 0.
default doublenormal(double sigma, double mean)
Generates a sample of the Normal distribution.
default doublenormal(double min, double max, double shift, double stretch)
Generates a sample of truncated Normal distribution.
Distribution normal(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublenormal(double min, double max, double shift, double stretch, Random r)
Generates a sample of truncated Normal distribution using the specified random number generator.
Distribution normal(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublenormal(double sigma, double mean, Random r)
Generates a sample of the Normal distribution using the specified random number generator.
default doublepareto(double alpha)
Generates a sample of the Pareto distribution with min set to 1.
default doublepareto(double alpha, double min)
Generates a sample of the Pareto distribution.
static doublepareto(double alpha, double min, Random r)
Generates a sample of the Pareto distribution using the specified random number generator.
default doublepert(double min, double max, double mode)
Generates a sample of the PERT distribution.
static doublepert(double min, double max, double mode, Random r)
Generates a sample of the PERT distribution using the specified random number generator.
default intpoisson(double lambda)
Generates a sample of the Poisson distribution.
default doublepoisson(double min, double max, double mean, double shift, double stretch)
Generates a sample of truncated Poisson distribution.
Distribution poisson(mean) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doublepoisson(double min, double max, double mean, double shift, double stretch, Random r)
Generates a sample of truncated Poisson distribution using the specified random number generator.
Distribution poisson(mean) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static intpoisson(double lambda, Random r)
Generates a sample of the Poisson distribution using the specified random number generator.
default doublerandom()
Generates a random value uniformly distributed on the interval [0,1), the upper bound is not included.
Please use uniform() function (has the same logic) instead, for not to get in confusion with Math.random() function (the latter shouldn't be used in models because it doesn't utilize random number generator of Engine and will result in not reproducible model runs).
default booleanrandomFalse(double p)
Generates false with the given probability p.
static booleanrandomFalse(double p, Random r)
Generates false with the given probability p using the specified random number generator.
For more details see randomFalse(double)
default <T extends Enum<T>>
T
randomFrom(Class<T> enumeration)
Returns the randomly chosen enumeration constant.
Throws NullPointerException if the given class is null or not an enumeration class
static <T extends Enum<T>>
T
randomFrom(Class<T> enumeration, Random r)
Returns the randomly chosen enumeration constant.
default <T> TrandomFrom(Iterable<T> collection)
Returns the randomly chosen element of the given collection.
For empty collections return null.
This result of this method is an equivalent of calling: collection.get( uniform_discr( collection.size() - 1 ) )
static <T> TrandomFrom(Iterable<T> collection, Random r)
Returns the randomly chosen element of the given collection.
default <T> TrandomFrom(T[] array)
Returns the randomly chosen element of the given array.
This result of this method is an equivalent of calling: array[ uniform_discr( array.length - 1 ) ]
static <T> TrandomFrom(T[] array, Random r)
Returns the randomly chosen element of the given array.
default <T> TrandomlyCreate(Class<? extends T>... classes)
Creates a randomly chosen object using one of the given constructors.
default <T> TrandomlyCreate(Supplier<? extends T>... constructors)
Creates a randomly chosen object using one of the given constructors.
static <T> TrandomlyCreate(Random r, Class<? extends T>... classes)
Creates a randomly chosen object using one of the given constructors.
static <T> TrandomlyCreate(Random r, Supplier<? extends T>... constructors)
Creates a randomly chosen object using one of the given constructors.
default booleanrandomTrue(double p)
Generates true with the given probability p.
static booleanrandomTrue(double p, Random r)
Generates true with the given probability p using the specified random number generator.
For more details see randomTrue(double)
default <T> TrandomWhere(Iterable<T> collection, Predicate<T> condition)
Returns the randomly chosen element of the given collection which meets the given condition.
For empty collections return null.
static <T> TrandomWhere(Iterable<T> collection, Predicate<T> condition, Random r)
Returns the randomly chosen element of the given collection which meets the given condition.
default <T> TrandomWhere(T[] array, Predicate<T> condition)
Returns the randomly chosen element of the given array which meets the given condition.
static <T> TrandomWhere(T[] array, Predicate<T> condition, Random r)
Returns the randomly chosen element of the given array which meets the given condition.
default doublerayleigh(double sigma)
Generates a sample of the Rayleigh distribution with min set to 0.
default doublerayleigh(double sigma, double min)
Generates a sample of the Rayleigh distribution.
static doublerayleigh(double sigma, double min, Random r)
Generates a sample of the Rayleigh distribution using the specified random number generator.
default voidshuffle(List<?> list)
Randomly permutes the specified list.
default doubletriangular(double min, double max)
Generates a sample of the Triangular distribution with mode set to (min + max)/2.
default doubletriangular(double min, double max, double mode)
Generates a sample of the Triangular distribution.
default doubletriangular(double min, double max, double left, double mode, double right)
Generates a sample of truncated Triangular distribution.
Distribution triangular(left, right, mode) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doubletriangular(double min, double max, double left, double mode, double right, Random r)
Generates a sample of truncated Triangular distribution using the specified random number generator.
Distribution triangular(left, right, mode) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
static doubletriangular(double min, double max, double mode, Random r)
Generates a sample of the Triangular distribution using the specified random number generator.
default doubletriangularAV(double average, double variability)
Generates a sample of the Triangular distribution with mode set to average.
Defines distribution in the form like "roughly this, +/-20%".
Is equivalent to triangular( average * (1 - variability), average * (1 + variability) ) .
static doubletriangularAV(double average, double variability, Random r)
Generates a sample of the Triangular distribution with mode set to average.
Defines distribution in the form like "roughly this, +/-20%".
Is equivalent to triangular( average * (1 - variability), average * (1 + variability) ) .
default doubleuniform()
Generates a random value uniformly distributed on the interval [0,1), the upper bound is not included.
default doubleuniform(double max)
Generates a sample of the Uniform distribution on the interval [0, max).
default doubleuniform(double min, double max)
Generates a sample of the Uniform distribution on the interval [min, max).
static doubleuniform(double min, double max, Random r)
Generates a sample of the Uniform distribution on the interval [min, max) using the specified random number generator.
static doubleuniform(Random r)
Generates a random value uniformly distributed on the interval [0,1), using the specified random number generator.
default intuniform_discr(int max)
Generates a sample of the Discrete Uniform distribution in the interval [0, max], both 0 and max included! Is equivalent to uniform_discr(0, max).
default intuniform_discr(int min, int max)
Generates a sample of the Discrete Uniform distribution on the interval [min, max], both min and max included!
static intuniform_discr(int min, int max, Random r)
Generates a sample of the Discrete Uniform distribution on the interval [min, max] using the specified random number generator, both 0 and max included! For more details see uniform_discr(int,int).
default doubleuniform_pos()
Generates a positive random value uniformly distributed on the interval (0,1).
static doubleuniform_pos(Random r)
Generates a positive random value uniformly distributed on the interval (0,1), using the specified random number generator.
default doubleweibull(double beta, double alpha)
Generates a sample of the Weibull distribution with min set to 0.
default doubleweibull(double alpha, double beta, double min)
Generates a sample of the Weibull distribution.
default doubleweibull(double min, double max, double alpha, double shift, double stretch)
Generates a sample of truncated Weibull distribution.
Distribution weibull(alpha, stretch, 0) is shifted to the right by shift and then truncated to fit in [min, max] interval.
static doubleweibull(double min, double max, double alpha, double shift, double stretch, Random r)
Generates a sample of truncated Weibull distribution using the specified random number generator.
Distribution weibull(alpha, stretch, 0) is shifted to the right by shift and then truncated to fit in [min, max] interval.
static doubleweibull(double alpha, double beta, double min, Random r)
Generates a sample of the Weibull distribution using the specified random number generator.

Field Details

RANDOM_BOUNDED_DISTRIBUTIONS_MAX_ITERATIONS

@AnyLogicInternalAPI
static final int RANDOM_BOUNDED_DISTRIBUTIONS_MAX_ITERATIONS
See Also:
Constant Field Values

Method Details

getDefaultRandomGenerator

Random getDefaultRandomGenerator()
Retrieves the random number generator used by all probability distributions by default, i.e. if no particular generator is specified in the call to a probability distribution function.
Returns:
the default random number generator.

uniform

default double uniform()
Generates a random value uniformly distributed on the interval [0,1), the upper bound is not included.
Returns:
the generated sample.

random

@AnyLogicInternalAPI
default double random()
Generates a random value uniformly distributed on the interval [0,1), the upper bound is not included.
Please use uniform() function (has the same logic) instead, for not to get in confusion with Math.random() function (the latter shouldn't be used in models because it doesn't utilize random number generator of Engine and will result in not reproducible model runs).
Returns:
the generated sample.
Since:
8.0

uniform

static double uniform(Random r)
Generates a random value uniformly distributed on the interval [0,1), using the specified random number generator.
Parameters:
r - the random number generator.
Returns:
the generated sample.

uniform_pos

default double uniform_pos()
Generates a positive random value uniformly distributed on the interval (0,1).
Returns:
the generated sample.

uniform_pos

static double uniform_pos(Random r)
Generates a positive random value uniformly distributed on the interval (0,1), using the specified random number generator.
Parameters:
r - the random number generator.
Returns:
the generated sample.

uniform

default double uniform(double max)
Generates a sample of the Uniform distribution on the interval [0, max). Is equivalent to uniform(0, max). For more details see uniform(double,double).
Parameters:
max - the maximum x value (excluded from the interval).
Returns:
the generated sample.

uniform

default double uniform(double min,
 double max)
Generates a sample of the Uniform distribution on the interval [min, max).

The Uniform distribution is a continuous distribution bounded on both sides, i.e. the sample lays in the interval [min,max). The probability density does not depend on the value of x. It is a special case of the Beta distribution. It is frequently called rectangular distribution (see Johnson et al).

The Uniform distribution is used to represent a random variable with constant likelihood of being in any small interval between min and max. Note that the probability of max value is 0; the max point never occurs.

Parameters:
min - the minimum x value (included into the interval).
max - the maximum x value (excluded from the interval).
Returns:
the generated sample.

uniform

static double uniform(double min,
 double max,
 Random r)
Generates a sample of the Uniform distribution on the interval [min, max) using the specified random number generator. For more details see uniform(double,double).
Parameters:
min - the minimum x value (included into the interval).
max - the maximum x value (excluded from the interval).
r - the random number generator.
Returns:
the generated sample.

uniform_discr

default int uniform_discr(int max)
Generates a sample of the Discrete Uniform distribution in the interval [0, max], both 0 and max included! Is equivalent to uniform_discr(0, max). For more details see uniform_discr(int,int).
Parameters:
max - the maximum x value (included into the interval).
Returns:
the generated sample.

uniform_discr

default int uniform_discr(int min,
 int max)
Generates a sample of the Discrete Uniform distribution on the interval [min, max], both min and max included!

The Discrete Uniform distribution is a discrete distribution bounded on [min, max] with constant probability at every value on or between the bounds. Sometimes called the discrete rectangular distribution, it arises when an event can have a finite and equally probable number of outcomes.

Parameters:
min - the minimum x value (included into the interval).
max - the maximum x value (also included into the interval).
Returns:
the generated sample.

uniform_discr

static int uniform_discr(int min,
 int max,
 Random r)
Generates a sample of the Discrete Uniform distribution on the interval [min, max] using the specified random number generator, both 0 and max included! For more details see uniform_discr(int,int).
Parameters:
min - the minimum x value (included into the interval).
max - the maximum x value (also included into the interval).
r - the random number generator.
Returns:
the generated sample.

randomTrue

default boolean randomTrue(double p)
Generates true with the given probability p. Is equivalent to uniform() < p. The probability of false is 1 - p correspondingly.
Parameters:
p - the probability of true.
Returns:
true with probability p, false with probability 1 - p.
See Also:
randomFalse(double)bernoulli(double)

randomTrue

static boolean randomTrue(double p,
 Random r)
Generates true with the given probability p using the specified random number generator.
For more details see randomTrue(double)
Parameters:
p - the probability of true.
r - the random number generator.
Returns:
true with probability p, false with probability 1 - p.
See Also:

randomFalse

default boolean randomFalse(double p)
Generates false with the given probability p. Is equivalent to uniform() >= p. The probability of true is 1 - p correspondingly.
Parameters:
p - the probability of false.
Returns:
false with probability p, true with probability 1 - p
See Also:
randomTrue(double)bernoulli(double)

randomFalse

static boolean randomFalse(double p,
 Random r)
Generates false with the given probability p using the specified random number generator.
For more details see randomFalse(double)
Parameters:
p - the probability of false.
r - the random number generator.
Returns:
false with probability p, true with probability 1 - p
See Also:

randomFrom

default <T> T randomFrom(Iterable<T> collection)
Returns the randomly chosen element of the given collection.
For empty collections return null.
This result of this method is an equivalent of calling: collection.get( uniform_discr( collection.size() - 1 ) )
Parameters:
collection - the collection to select an element from
Returns:
the randomly chosen element or null, if collection is empty
See Also:

randomFrom

static <T> T randomFrom(Iterable<T> collection,
 Random r)
Returns the randomly chosen element of the given collection. Uses the specified random number generator to choose the element.
For more details see randomFrom(Iterable)
Parameters:
collection - the collection to select an element from
r - the random number generator.
Returns:
the randomly chosen element or null, if collection is empty

randomWhere

default <T> T randomWhere(Iterable<T> collection,
 Predicate<T> condition)
Returns the randomly chosen element of the given collection which meets the given condition.
For empty collections return null.
Parameters:
collection - the collection to select an element from
condition - the condition to test
Returns:
the randomly chosen element or null, if collection is empty
See Also:
randomFrom(Iterable)

randomWhere

static <T> T randomWhere(Iterable<T> collection,
 Predicate<T> condition,
 Random r)
Returns the randomly chosen element of the given collection which meets the given condition. Uses the specified random number generator to choose the element.
For more details see randomWhere(Iterable, Predicate)
Parameters:
collection - the collection to select an element from
condition - the condition to test
r - the random number generator.
Returns:
the randomly chosen element or null, if collection is empty

randomFrom

default <T> T randomFrom(T[] array)
Returns the randomly chosen element of the given array.
This result of this method is an equivalent of calling: array[ uniform_discr( array.length - 1 ) ]
Parameters:
array - the array to select an element from
Returns:
the randomly chosen element or null, if the array is empty
See Also:

randomFrom

static <T> T randomFrom(T[] array,
 Random r)
Returns the randomly chosen element of the given array. Uses the specified random number generator to choose the element.
For more details see #randomFrom(T[])
Parameters:
array - the array to select an element from
r - the random number generator
Returns:
the randomly chosen element or null, if the array is empty

randomWhere

default <T> T randomWhere(T[] array,
 Predicate<T> condition)
Returns the randomly chosen element of the given array which meets the given condition.
Parameters:
array - the array to select an element from
condition - the condition to test
Returns:
the randomly chosen element or null, if the array is empty
See Also:
randomFrom(Object[])

randomWhere

static <T> T randomWhere(T[] array,
 Predicate<T> condition,
 Random r)
Returns the randomly chosen element of the given array which meets the given condition. Uses the specified random number generator to choose the element.
For more details see #randomFrom(T[])
Parameters:
array - the array to select an element from
condition - the condition to test
r - the random number generator
Returns:
the randomly chosen element or null, if the array is empty

randomFrom

default <T extends Enum<T>> T randomFrom(Class<T> enumeration)
Returns the randomly chosen enumeration constant.
Throws NullPointerException if the given class is null or not an enumeration class
Parameters:
enumeration - the enumeration class
r - the random number generator
Returns:
the randomly chosen enumeration constant

randomFrom

static <T extends Enum<T>> T randomFrom(Class<T> enumeration,
 Random r)
Returns the randomly chosen enumeration constant. Uses the specified random number generator to choose the constant.
Throws NullPointerException if the given class is null or not an enumeration class
Parameters:
enumeration - the enumeration class
r - the random number generator
Returns:
the randomly chosen enumeration constant

randomlyCreate

default <T> T randomlyCreate(Supplier<? extends T>... constructors)
Creates a randomly chosen object using one of the given constructors. Example usage (in the Source.newCar field of Rail Library):
 randomlyCreate(
        OpenCar::new,
        BoxCar::new,
        HopperCar::new
 )
Parameters:
constructors - constructors or other functions / lambda expressions which return object instances
Returns:
randomly chosen object, or null if there are no constructors provided
Since:
7.3.5

randomlyCreate

default <T> T randomlyCreate(Class<? extends T>... classes)
Creates a randomly chosen object using one of the given constructors. Example usage (in the Source.newCar field of Rail Library):
 randomlyCreate(
        OpenCar.class,
        BoxCar.class,
        HopperCar.class
 )
Parameters:
classes - object classes
Returns:
randomly chosen and created object, or null if there are no classes provided
Since:
7.3.5

randomlyCreate

static <T> T randomlyCreate(Random r,
 Supplier<? extends T>... constructors)
Creates a randomly chosen object using one of the given constructors. The choice is made using the specified random number generator. Example usage (in the Source.newCar field of Rail Library):
 randomlyCreate(myRandom, OpenCar::new, BoxCar::new, HopperCar::new)
 
Parameters:
constructors - constructors or other functions / lambda expressions which return object instances
Returns:
randomly chosen object, or null if there are no constructors provided
Since:
7.3.5

randomlyCreate

static <T> T randomlyCreate(Random r,
 Class<? extends T>... classes)
Creates a randomly chosen object using one of the given constructors. The choice is made using the specified random number generator. Example usage (in the Source.newCar field of Rail Library):
 randomlyCreate(myRandom, OpenCar.class, BoxCar.class, HopperCar.class)
 
Parameters:
classes - object classes
Returns:
randomly chosen and created object, or null if there are no classes provided
Since:
7.3.5

shuffle

default void shuffle(List<?> list)
Randomly permutes the specified list. All permutations occur with equal likelihood.
This implementation traverses the list backwards, from the last element up to the second, repeatedly swapping a randomly selected element into the "current position". Elements are randomly selected from the portion of the list that runs from the first element to the current position, inclusive.
This method runs in linear time.
Parameters:
list - the list to be shuffled.

bernoulli

default int bernoulli(double p)
Generates a sample of the Bernoulli distribution, i.e. 1 with probability p and 0 with probability 1 - p.
Parameters:
p - the probability of 1.
Returns:
the generated sample.

bernoulli

static int bernoulli(double p,
 Random r)
Generates a sample of the Bernoulli distribution using the specified random number generator. For more details see bernoulli(double).
Parameters:
p - the probability of 1.
r - the random number generator.
Returns:
the generated sample.

beta

default double beta(double p,
 double q)
Generates a sample of the Beta distribution with min set to 0 and max set to 1. Is equivalent to beta(p, q, 0, 1). For more details see beta(double,double,double,double).
Parameters:
p - the lower shape parameter > 0.
q - the upper shape parameter > 0.
Returns:
the generated sample.

beta

default double beta(double p,
 double q,
 double min,
 double max)
Generates a sample of the Beta distribution.

The Beta distribution is a continuous distribution that has both upper and lower finite bounds. Because many real situations can be bounded in this way, the Beta distribution can be used empirically to estimate the actual distribution before much data is available. Even when data is available, the Beta distribution should fit most data in a reasonable fashion, although it may not be the best fit. The Uniform distribution is a special case of the Beta distribution with p, q = 1.

The Beta distribution can approach zero or infinity at either of its bounds, with p controlling the lower bound and q controlling the upper bound. Values of p, q < 1 cause the Beta distribution to approach infinity at that bound. Values of p, q > 1 cause the Beta distribution to be finite at that bound.

Beta distributions have many, many uses. As summarized in Johnson et al Beta distributions have been used to model distributions of hydrologic variables, logarithm of aerosol sizes, activity time in PERT analysis, isolation data in photovoltaic system analysis, porosity / void ratio of soil, phase derivatives in communication theory, size of progeny in Escherchia Coli, dissipation rate in breakage models, proportions in gas mixtures, steady-state reflectivity, clutter and power of radar signals, construction duration, particle size, tool wear, and others. Many of these uses occur because of the doubly bounded nature of the Beta distribution.

Parameters:
p - the lower shape parameter > 0.
q - the upper shape parameter > 0.
min - the minimum x value.
max - the maximum x value.
Returns:
the generated sample.

beta

default double beta(double min,
 double max,
 double p,
 double q,
 double shift,
 double stretch)
Generates a sample of truncated Beta distribution.
Distribution beta(p, q, 0, 1) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see beta(double, double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
p - the lower shape parameter > 0. Also known as alpha parameter
q - the upper shape parameter > 0. Also known as beta parameter
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample.

beta

static double beta(double p,
 double q,
 double min,
 double max,
 Random r)
Generates a sample of the Beta distribution using the specified random number generator. For more details see beta(double,double,double,double).
Parameters:
p - the lower shape parameter > 0.
q - the upper shape parameter > 0.
min - the minimum x value.
max - the maximum x value.
r - the random number generator.
Returns:
the generated sample.

beta

static double beta(double min,
 double max,
 double p,
 double q,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Beta distribution using the specified random number generator.
Distribution beta(p, q, 0, 1) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see beta(double, double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
p - the lower shape parameter > 0. Also known as alpha parameter
q - the upper shape parameter > 0. Also known as beta parameter
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
r - the random number generator.
Returns:
the generated sample.

binomial

default int binomial(double p)
Generates a sample of the Binomial distribution with n set to 1. Is equivalent to binomial(p, 1). For more details see binomial(double,int).
Parameters:
p - the p parameter of the Binomial distribution, i.e. the probability of the event occurrence.
Returns:
the generated sample.

binomial

default int binomial(double p,
 int n)
Generates a sample of the Binomial distribution.
Parameters:
p - the probability of the event occurrence.
n - the number of trials.
Returns:
the generated sample.

binomial

default double binomial(double min,
 double max,
 double p,
 double n,
 double shift,
 double stretch)
Generates a sample of truncated Binomial distribution.
Distribution binomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see binomial(double, int)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
p - the probability of the event occurrence.
n - the number of trials. If n is not an integer it will be rounded to the nearest integer.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample, note that in common case it is not an integer (because of stretching).

binomial

static int binomial(double p,
 int n,
 Random r)
Generates a sample of the Binomial distribution using the specified random number generator.
Parameters:
p - the probability of the event occurrence.
n - the number of trials.
r - the random number generator.
Returns:
the generated sample.

binomial

static double binomial(double min,
 double max,
 double p,
 double n,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Binomial distribution using the specified random number generator.
Distribution binomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see binomial(double, int)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
p - the probability of the event occurrence.
n - the number of trials. If n is not an integer it will be rounded to the nearest integer.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
r - the random number generator.
Returns:
the generated sample, note that in common case it is not an integer (because of stretching).

cauchy

default double cauchy(double lambda)
Generates a sample of the Cauchy distribution with theta set to 0. Is equivalent to cauchy(lambda, 0). For more details see cauchy(double,double).
Parameters:
lambda - the scaling parameter > 0.
Returns:
the generated sample.

cauchy

default double cauchy(double lambda,
 double theta)
Generates a sample of the Cauchy distribution.

The Cauchy distribution is an unbounded continuous distribution that has a sharp central peak but significantly broad tails. The tails are much heavier than the tails of the Normal distribution.

The Cauchy distribution can be used to represent the ratio of two equally distributed parameters in certain cases, e.g. the ratio of two normal parameters. This distribution has no finite moments because of its extensive tails. Thus it can also be used to generate wildly divergent data a long as the data has a central tendency.

Parameters:
lambda - the scaling parameter > 0.
theta - the mode, or central peak position.
Returns:
the generated sample.

cauchy

static double cauchy(double lambda,
 double theta,
 Random r)
Generates a sample of the Cauchy distribution using the specified random number generator. For more details see cauchy(double,double).
Parameters:
lambda - the scaling parameter > 0.
theta - the mode, or central peak position.
r - the random number generator.
Returns:
the generated sample.

chi2

default double chi2(double nu)
Generates a sample of the Chi Squared distribution with min set to 0. Is equivalent to chi2(nu, 0). For more details see chi2(double,double)
Parameters:
nu - the shape parameter.
Returns:
the generated sample.

chi2

default double chi2(double nu,
 double min)
Generates a sample of the Chi Squared distribution.

The Chi Squared is a continuous distribution bounded on the lower side. Note that the Chi Squared distribution is a subset of the Gamma distribution with beta=2 and alpha=nμ/2. Like the Gamma distribution, it has three distinct regions. For nμ=2, the Chi Squared distribution reduces to the Exponential distribution, starting at a finite value at minimum x and decreasing monotonically thereafter. For nμ<2, the Chi Squared distribution tends to infinity at minimum x and decreases monotonically for increasing x. For nμ>2, the Chi Squared distribution is 0 at minimum x, peaks at a value that depends on nμ, decreasing monotonically thereafter.

Because the Chi Squared distribution does not have a scaling parameter, its utilization is somewhat limited. Frequently, this distribution will try to represent data with a clustered distribution with nμ less than 2. However, it can be viewed as the distribution of the sum of squares of independent unit normal variables with nμ degrees of freedom and is used in many statistical tests.

Examples of each of the regions of the Chi Squared distribution are shown above. Note that the peak of the distribution moves away from the minimum value for increasing nu, but with a much broader distribution.

Parameters:
nu - the shape parameter.
min - the minimum x value.
Returns:
the generated sample.

chi2

static double chi2(double nu,
 double min,
 Random r)
Generates a sample of the Chi Squared distribution using the specified random number generator. For more details see chi2(double,double).
Parameters:
nu - the shape parameter.
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

erlang

default double erlang(double beta,
 int m)
Generates a sample of the Erlang distribution with min set to 0. Is equivalent to erlang(beta, m, 0). For more details see erlang(double,int,double)/
Parameters:
beta - the scale factor > 0.
m - the shape factor (positive integer).
Returns:
the generated sample.

erlang

default double erlang(double beta,
 int m,
 double min)
Generates a sample of the Erlang distribution.

The Erlang distribution is a continuous distribution bounded on the lower side. It is a special case of the Gamma distribution where the parameter, m, is restricted to a positive integer. As such, the Erlang distribution has no region where F(x) tends to infinity at the minimum value of x [m<1], but does have a special case at m=1, where it reduces to the Exponential distribution.

The Erlang distribution has been used extensively in reliability and in queuing theory, thus in discrete event simulation, because it can be viewed as the sum of m exponentially distributed random variables, each with mean beta.

Parameters:
beta - the scale factor > 0.
m - the shape factor (positive integer).
min - the minimum x value.
Returns:
the generated sample.

erlang

static double erlang(double beta,
 int m,
 double min,
 Random r)
Generates a sample of the Erlang distribution using the specified random number generator. For more details see erlang(double,int,double).
Parameters:
beta - the scale factor > 0.
m - the shape factor (positive integer).
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

exponential

default double exponential()
Generates a sample of the Exponential distribution with lambda set to 1 and min set to 0. Is equivalent to exponential(1, 0). For more details see exponential(double,double)
Returns:
the generated sample.

exponential

default double exponential(double lambda)
Generates a sample of the Exponential distribution with min set to 0. Is equivalent to exponential(lambda, 0). For more details see exponential(double,double).
Parameters:
lambda - the shape parameter.
Returns:
the generated sample.

exponential

default double exponential(double lambda,
 double min)
Generates a sample of the Exponential distribution.

The Exponential distribution is a continuous distribution bounded on the lower side. It's shape is always the same, starting at a finite value at the minimum and continuously decreasing at larger x. The Exponential distribution decreases rapidly for increasing x.

The Exponential distribution is frequently used to represent the time between random occurrences, such as the time between arrivals at a specific location in a queuing model or the time between failures in reliability models. It has also been used to represent the services times of a specific operation. Further, it serves as an explicit manner in which the time dependence on noise may be treated. As such, these models are making explicit use of the lack of history dependence of the exponential distribution; it has the same set of probabilities when shifted in time. Even when Exponential models are known to be inadequate to describe the situation, their mathematical tractability provides a good starting point. Later, a more complex distribution such as Erlang or Weibull may be investigated.

Parameters:
lambda - the shape parameter.
min - the minimum x value.
Returns:
the generated sample.

exponential

default double exponential(double min,
 double max,
 double shift,
 double stretch)
Generates a sample of truncated Exponential distribution.
Distribution exponential(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see exponential(double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample

exponential

static double exponential(double lambda,
 double min,
 Random r)
Generates a sample of the Exponential distribution using the specified random number generator. For more details see exponential(double,double).
Parameters:
lambda - the shape parameter.
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

exponential

static double exponential(double min,
 double max,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Exponential distribution using the specified random number generator.
Distribution exponential(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see exponential(double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
r - the random number generator.
Returns:
the generated sample

gamma

default double gamma(double alpha,
 double beta)
Generates a sample of the Gamma distribution with min set to 0. Is equivalent to gamma(alpha, beta, 0). For more details see gamma(double,double,double).
Parameters:
alpha - the shape parameter > 0.
beta - the scale parameter > 0.
Returns:
the generated sample.

gamma

default double gamma(double alpha,
 double beta,
 double min)
Generates a sample of the Gamma distribution.

The Gamma distribution is a continuous distribution bounded at the lower side. It has three distinct regions. For alpha=1, the Gamma distribution reduces to the Exponential distribution, starting at a finite value at minimum x and decreasing monotonically thereafter. For alpha<1, the Gamma distribution tends to infinity at minimum x and decreases monotonically for increasing x. For alpha>1, the Gamma distribution is 0 at minimum x, peaks at a value that depends on both alpha and beta, decreasing monotonically thereafter. If alpha is restricted to positive integers, the Gamma distribution is reduced to the Erlang distribution.

Note that the Gamma distribution also reduces to the Chi Squared distribution for min=0, beta=2, and alpha=nμ/2. It can then be viewed as the distribution of the sum of squares of independent unit normal variables, with nμ degrees of freedom and is used in many statistical tests.

The Gamma distribution can also be used to approximate the Normal distribution, for large alpha, while maintaining its strictly positive values of x [actually (x-min)].

The Gamma distribution has been used to represent lifetimes, lead times, personal income data, a population about a stable equilibrium, interarrival times, and service times. In particular, it can represent lifetime with redundancy (see Johnson, Shooman).

Examples of each of the regions of the Gamma distribution are shown above. Note the peak of the distribution moving away from the minimum value for increasing alpha, but with a much broader distribution.

Parameters:
alpha - the shape parameter > 0.
beta - the scale parameter > 0.
min - the minimum x value.
Returns:
the generated sample.

gamma

default double gamma(double min,
 double max,
 double alpha,
 double shift,
 double stretch)
Generates a sample of truncated Gamma distribution.
Distribution gamma(alpha, 1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see gamma(double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
alpha - the shape parameter > 0. Also known as order. If less than 1, then 1 will be used.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample

gamma

static double gamma(double alpha,
 double beta,
 double min,
 Random r)
Generates a sample of the Gamma distribution using the specified random number generator. For more details see gamma(double,double,double).
Parameters:
alpha - the shape parameter > 0.
beta - the scale parameter > 0.
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

gamma

static double gamma(double min,
 double max,
 double alpha,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Gamma distribution using the specified random number generator.
Distribution gamma(alpha, 1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see gamma(double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
alpha - the shape parameter > 0. Also known as order. If less than 1, then 1 will be used.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
r - the random number generator.
Returns:
the generated sample

geometric

default int geometric(double p)
Generates a sample of the Geometric distribution.

The Geometric distribution is a discrete distribution bounded at 0 and unbounded on the high side. It is a special case of the Negative Binomial distribution. In particular, it is the direct discrete analog for the continuous Exponential distribution. The Geometric distribution has no history dependence, its probability at any value being independent of a shift along the axis.

Generated sample has the distribution of the number X of trials needed to get one success. Returned values are { 1, 2, 3, ... }. If you need 'geometric' in terms of "number of failures before the 1st success", please use the expression geometric( p ) - 1.

The Geometric distribution has been used for inventory demand, marketing survey returns, a ticket control problem, and meteorological models.

Parameters:
p - the probability of occurrence.
Returns:
the generated sample.

geometric

static int geometric(double p,
 Random r)
Generates a sample of the Geometric distribution using the specified random number generator. For more details see geometric(double).
Parameters:
p - the probability of occurrence.
r - the random number generator.
Returns:
the generated sample.

hypergeometric

default int hypergeometric(int ss,
 int dn,
 int ps)
Generates a sample of the Hypergeometric distribution.

The Hypergeometric distribution is a discrete distribution bounded by [0,s]. It describes the number of defects, x, in a sample of size s from a population of size N which has m total defects. The ratio of m/N = p is sometimes used rather than m to describe the probability of a defect. Note that defects may be interpreted as successes, in which case x is the number of failures until (s-x) successes. The sample is taken without replacement.

The Hypergeometric distribution is used to describe sampling from a population where an estimate of the total number of defects is desired. It has also been used to estimate the total population of species from a tagged subset. However, estimates of all three parameters from a data set are notoriously fickle and error prone, so use of these parameters to estimate a physical quantity without specifying at least one of the parameters is not recommended. (see Johnson et. al.1)

Parameters:
ss - the sample size.
dn - the number of defects in the population.
ps - the size of the population.
Returns:
the generated sample.

hypergeometric

static int hypergeometric(int ss,
 int dn,
 int ps,
 Random r)
Generates a sample of the Hypergeometric distribution using the specified random number generator. For more details see hypergeometric(int,int,int).
Parameters:
ss - the sample size.
dn - the number of defects in the population.
ps - the size of the population.
Returns:
the generated sample.

gumbel1

default double gumbel1(double a,
 double b)
Generates a sample of the Type I Gumbel distribution.
This distribution has the form
p(x) = a b exp(-(b exp(-ax) + ax))
Parameters:
a - the 'a' parameter
b - the 'b' parameter
Returns:
the generated sample.

gumbel1

static double gumbel1(double a,
 double b,
 Random r)
Generates a sample of the Type I Gumbel distribution using the specified random number generator. For more details see gumbel1(double,double).
Parameters:
a - the 'a' parameter
b - the 'b' parameter
r - the random number generator.
Returns:
the generated sample.

gumbel2

default double gumbel2(double a,
 double b)
Generates a sample of the Type II Gumbel distribution.
This distribution has the form
p(x) = b a x^-(a+1) exp(-b x^-a))
Parameters:
a - the 'a' parameter
b - the 'b' parameter
Returns:
the generated sample.

gumbel2

static double gumbel2(double a,
 double b,
 Random r)
Generates a sample of the Type II Gumbel distribution using the specified random number generator. For more details see gumbel2(double,double).
Parameters:
a - the 'a' parameter
b - the 'b' parameter
r - the random number generator.
Returns:
the generated sample.

laplace

default double laplace(double phi,
 double theta)
Generates a sample of the Laplace distribution.

The Laplace distribution, sometimes called the double exponential distribution, is an unbounded continuous distribution that has a very sharp central peak, located at theta. The distribution scales with phi.

The Laplace distribution can be used to describe the difference of two independent, and equally distributed, exponentials. It is also used in error analysis. (see Johnson et.al.1)

Parameters:
phi - the scaling parameter.
theta - the mode, or central peak position.
Returns:
the generated sample.

laplace

static double laplace(double phi,
 double theta,
 Random r)
Generates a sample of the Laplace distribution using the specified random number generator. For more details see laplace(double,double).
Parameters:
phi - the scaling parameter.
theta - the mode, or central peak position.
r - the random number generator.
Returns:
the generated sample.

logarithmic

default int logarithmic(double theta)
Generates a sample of the Logarithmic distribution.

The Logarithmic distribution is a discrete distribution bounded by [1,...]. Theta is related to the sample size and the mean.

The Logarithmic distribution is used to describe the diversity of a sample, that is, how many of a given type of thing are contained in a sample of things. For instance, this distribution has been used to describe the number of individuals of a given species in a sampling of mosquitoes, or the number of parts of a given type in a sampling of inventory. (see Johnson et.al.1)

Parameters:
theta - the shape/scale parameter 0<theta<1
Returns:
the generated sample.

logarithmic

static int logarithmic(double theta,
 Random r)
Generates a sample of the Logarithmic distribution using the specified random number generator. For more details see logarithmic(double).
Parameters:
theta - the shape/scale parameter 0<theta<1
r - the random number generator.
Returns:
the generated sample.

logistic

default double logistic(double beta,
 double alpha)
Generates a sample of the Logistic distribution.

The Logistic distribution is an unbounded continuous distribution which is symmetrical about its mean [and shift parameter], alpha. The shape of the Logistic distribution is very much like the Normal distribution, except that the Logistic distribution has broader tails.

The Logistic function is most often used a growth model: for populations, for weight gain, for business failure, etc. The Logistic distribution can be can be used to test for the suitability of such a model, with transformation to get back to the minimum and maximum values for the Logistic function. Occasionally, the Logistic function is used in place of the Normal function where exceptional cases play a larger role.(see Johnson et. al.1)

Parameters:
beta - the scale parameter > 0.
alpha - the shift parameter.
Returns:
the generated sample.

logistic

static double logistic(double beta,
 double alpha,
 Random r)
Generates a sample of the Logistic distribution using the specified random number generator. For more details see logistic(double,double).
Parameters:
beta - the scale parameter > 0.
alpha - the shift parameter.
r - the random number generator.
Returns:
the generated sample.

lognormal

default double lognormal(double mu,
 double sigma,
 double min)
Generates a sample of the Lognormal distribution.

The Lognormal distribution is a continuous distribution bounded on the lower side. It is always 0 at minimum x, rising to a peak that depends on both mu and sigma, then decreasing monotonically for increasing x.

By definition, the natural logarithm of a Lognormal random variable is a Normal random variable. Its parameters are usually given in terms of this included Normal.

The Lognormal distribution can also be used to approximate the Normal distribution, for small sigma, while maintaining its strictly positive values of x [actually (x-min)].

The Lognormal distribution is used in many different areas including the distribution of particle size in naturally occurring aggregates, dust concentration in industrial atmospheres, the distribution of minerals present in low, concentrations, duration of sickness absence, physicians' consultant time, lifetime distributions in reliability, distribution of income, employee retention, and many applications modeling weight, height, etc.(see Johnson et. al.1)

Parameters:
mu - the mean of the included Normal.
sigma - the standard deviation of the included Normal.
min - the minimum x value.
Returns:
the generated sample.

lognormal

static double lognormal(double mu,
 double sigma,
 double min,
 Random r)
Generates a sample of the Lognormal distribution using the specified random number generator. For more details see lognormal(double,double,double).
Parameters:
mu - the mean of the included Normal.
sigma - the standard deviation of the included Normal.
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

negativeBinomial

default int negativeBinomial(double p,
 double n)
Generates a sample of the Negative Binomial distribution.

The Negative Binomial distribution is a discrete distribution bounded on the low side at 0 and unbounded on the high side. The Negative Binomial distribution reduces to the Geometric Distribution for n = 1. The Negative Binomial distribution gives the total number of trials, x, to get k events (failures...), each with the constant probability, p, of occurring.

The Negative Binomial distribution has many uses; some occur because it provides a good approximation for the sum or mixing of other discrete distributions. By itself, it is used to model accident statistics, birth-and-death processes, market research and consumer expenditure, lending library data, biometrical data, and many others. (see Johnson et. al.1)

Parameters:
p - the probability of event (in the interval (0,1)).
n - the number of desired events.
Returns:
the generated sample.

negativeBinomial

default double negativeBinomial(double min,
 double max,
 double p,
 double n,
 double shift,
 double stretch)
Generates a sample of truncated Negative Binomial distribution.
Distribution negativeBinomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see negativeBinomial(double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
p - the probability of the event occurrence.
n - the number of trials. If n is not an integer it will be rounded to the nearest integer.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample

negativeBinomial

static int negativeBinomial(double p,
 double n,
 Random r)
Generates a sample of the Negative Binomial distribution using the specified random number generator. For more details see negativeBinomial(double,double).
Parameters:
p - the probability of event (in the interval (0,1)).
n - the number of desired events.
r - the random number generator.
Returns:
the generated sample.

negativeBinomial

static double negativeBinomial(double min,
 double max,
 double p,
 double n,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Negative Binomial distribution using the specified random number generator.
Distribution negativeBinomial(p, n) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see negativeBinomial(double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
p - the probability of the event occurrence.
n - the number of trials. If n is not an integer it will be rounded to the nearest integer.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
r - the random number generator.
Returns:
the generated sample

normal

default double normal()
Generates a sample of the Normal distribution with mean set to 0 and sigma set to 1. Is equivalent to normal(1, 0). For more details see normal(double,double).
Returns:
the generated sample.

normal

default double normal(double sigma)
Generates a sample of the Normal distribution with mean set to 0. Is equivalent to normal(sigma, 0). For more details see normal(double,double)
Parameters:
sigma - the shape parameter = standard deviation.
Returns:
the generated sample.

normal

default double normal(double sigma,
 double mean)
Generates a sample of the Normal distribution.

The Normal distribution is an unbounded continuous distribution. It is sometimes called a Gaussian distribution or the bell curve. Because of its property of representing an increasing sum of small, independent errors, the Normal distribution finds many, many uses in statistics. It is wrongly used in many situations. Possibly, the most important test in the fitting of analytical distributions is the elimination of the Normal distribution as a possible candidate.

The Normal distribution is used as an approximation for the Binomial distribution when the values of n, p are in the appropriate range. The Normal distribution is frequently used to represent symmetrical data, but suffers from being unbounded in both directions. If the data is known to have a lower bound, it may be better represented by suitable parameterization of the Lognormal, Weibull or Gamma distributions. If the data is known to have both upper and lower bounds, the Beta distribution can be used, although much work has been done on truncated Normal distributions.

Parameters:
sigma - the shape parameter = standard deviation.
mean - the shift parameter = mean value.
Returns:
the generated sample.

normal

default double normal(double min,
 double max,
 double shift,
 double stretch)
Generates a sample of truncated Normal distribution.
Distribution normal(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see normal(double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right = mean value
stretch - the stretch parameter that indicates how much the distribution will be stretched = standard deviation
Returns:
the generated sample

normal

static double normal(double sigma,
 double mean,
 Random r)
Generates a sample of the Normal distribution using the specified random number generator. For more details see normal(double,double)
Parameters:
sigma - the shape parameter = standard deviation.
mean - the shift parameter = mean value.
r - the random number generator.
Returns:
the generated sample.

normal

static double normal(double min,
 double max,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Normal distribution using the specified random number generator.
Distribution normal(1, 0) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see normal(double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right = mean value
stretch - the stretch parameter that indicates how much the distribution will be stretched = standard deviation
r - the random number generator.
Returns:
the generated sample

pareto

default double pareto(double alpha)
Generates a sample of the Pareto distribution with min set to 1. Is equivalent to pareto(alpha, 1). For more details see pareto(double,double)
Parameters:
alpha - the scale parameter > 0.
Returns:
the generated sample.

pareto

default double pareto(double alpha,
 double min)
Generates a sample of the Pareto distribution.

The Pareto distribution is a continuous distribution bounded on the lower side. It has a finite value at the minimum x and decreases monotonically for increasing x. A Pareto random variable is the exponential of an Exponential random variable, and possesses many of the same characteristics.

The Pareto distribution has, historically, been used to represent the income distribution of a society. It is also used to model many empirical phenomena with very long right tails, such as city population sizes, occurrence of natural resources, stock price fluctuations, size of firms, brightness of comets, and error clustering in communication circuits.

The shape of the Pareto curve changes slowly with alpha, but the tail of the distribution increases dramatically with decreasing alpha.

Parameters:
alpha - the scale parameter > 0.
min - the minimum x value.
Returns:
the generated sample.

pareto

static double pareto(double alpha,
 double min,
 Random r)
Generates a sample of the Pareto distribution using the specified random number generator. For more details see pareto(double,double).
Parameters:
alpha - the scale parameter > 0.
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

pert

default double pert(double min,
 double max,
 double mode)
Generates a sample of the PERT distribution.

The PERT distribution is a continuous distribution bounded on both sides. Being an alternative distribution to the Triangular, it has the same three inputs, Minimum, Most Likely, and Maximum, but is a smooth curve that puts less emphasis on extreme values.

The PERT distribution is often used in risk analysis applications, e.g. in Monte Carlo simulations to assess cost and project duration risks.

Parameters:
min - the minimum x value.
max - the maximum x value.
mode - the most likely x value.
Returns:
the generated sample.

pert

static double pert(double min,
 double max,
 double mode,
 Random r)
Generates a sample of the PERT distribution using the specified random number generator. For more details see pert(double, double, double)
Parameters:
min - the minimum x value.
mode - the most likely x value.
max - the maximum x value.
r - the random number generator.
Returns:
the generated sample.

poisson

default int poisson(double lambda)
Generates a sample of the Poisson distribution.

The Poisson distribution is a discrete distribution bounded at 0 on the low side and unbounded on the high side. The Poisson distribution is a limiting form of the Hypergeometric distribution.

The Poisson distribution finds frequent use because it represents the infrequent occurrence of events whose rate is constant. This includes many types of events in time or space such as arrivals of telephone calls, defects in semiconductor manufacturing, defects in all aspects of quality control, molecular distributions, stellar distributions, geographical distributions of plants, shot noise, etc. It is an important starting point in queuing theory and reliability theory. Note that the time between arrivals (defects) is Exponentially distributed, which makes this distribution a particularly convenient starting point even when the process is more complex.

The Poisson distribution peaks near lambda and falls off rapidly on either side.

Parameters:
lambda - the rate of occurrence.
Returns:
the generated sample.

poisson

default double poisson(double min,
 double max,
 double mean,
 double shift,
 double stretch)
Generates a sample of truncated Poisson distribution.
Distribution poisson(mean) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see poisson(double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
mean - the mean value for the distribution = rate of event occurrence
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample, note that in common case it is not an integer (because of stretching).

poisson

static int poisson(double lambda,
 Random r)
Generates a sample of the Poisson distribution using the specified random number generator. For more details see poisson(double).
Parameters:
lambda - the rate of occurrence.
r - the random number generator.
Returns:
the generated sample.

poisson

static double poisson(double min,
 double max,
 double mean,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Poisson distribution using the specified random number generator.
Distribution poisson(mean) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see poisson(double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
mean - the mean value for the distribution = rate of event occurrence
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
r - the random number generator.
Returns:
the generated sample, note that in common case it is not an integer (because of stretching).

rayleigh

default double rayleigh(double sigma)
Generates a sample of the Rayleigh distribution with min set to 0. Is equivalent to rayleigh(sigma, 0). For more details see rayleigh(double,double)
Parameters:
sigma - the scale parameter > 0.
Returns:
the generated sample.

rayleigh

default double rayleigh(double sigma,
 double min)
Generates a sample of the Rayleigh distribution.

The Rayleigh distribution is a continuous distribution bounded on the lower side. It is a special case of the Weibull distribution with alpha =2 and beta/sqrt(2) =sigma. Because of the fixed shape parameter, the Rayleigh distribution does not change shape although it can be scaled.

The Rayleigh distribution is frequently used to represent lifetimes because its hazard rate increases linearly with time, e.g. the lifetime of vacuum tubes. This distribution also finds application in noise problems in communications.

Parameters:
sigma - the scale parameter > 0.
min - the minimum x value.
Returns:
the generated sample.

rayleigh

static double rayleigh(double sigma,
 double min,
 Random r)
Generates a sample of the Rayleigh distribution using the specified random number generator. For more details see rayleigh(double,double)
Parameters:
sigma - the scale parameter > 0.
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

triangularAV

default double triangularAV(double average,
 double variability)
Generates a sample of the Triangular distribution with mode set to average.
Defines distribution in the form like "roughly this, +/-20%".
Is equivalent to triangular( average * (1 - variability), average * (1 + variability) ) . For more details see triangular(double,double,double).
Parameters:
average - the most likely x value
variability - the percent [0...1] of average representing the half of distribution range, where the generated sample falls
Returns:
the generated sample.
Since:
7.0

triangularAV

static double triangularAV(double average,
 double variability,
 Random r)
Generates a sample of the Triangular distribution with mode set to average.
Defines distribution in the form like "roughly this, +/-20%".
Is equivalent to triangular( average * (1 - variability), average * (1 + variability) ) . For more details see triangular(double, double, double, Random). Uses the specified random number generator.
Parameters:
average - the most likely x value
variability - the percent [0...1] of average representing the half of distribution range, where the generated sample falls
r - the random number generator.
Returns:
the generated sample.
Since:
7.1

triangular

default double triangular(double min,
 double max)
Generates a sample of the Triangular distribution with mode set to (min + max)/2. Is equivalent to triangular(min, (min + max)/2, max). For more details see triangular(double,double,double).
Parameters:
min - the minimum x value.
max - the maximum x value.
Returns:
the generated sample.

triangular

default double triangular(double min,
 double max,
 double mode)
Generates a sample of the Triangular distribution.

The Triangular distribution is a continuous distribution bounded on both sides.

The Triangular distribution is often used when no or little data is available; it is rarely an accurate representation of a data set. However, it is employed as the functional form of regions for fuzzy logic due to its ease of use.

The Triangular distribution can take on very skewed forms including negative skewness. For the exceptional cases where the mode is either the min or max, the Triangular distribution becomes a right triangle.

Parameters:
min - the minimum x value.
max - the maximum x value.
mode - the most likely x value.
Returns:
the generated sample.

triangular

default double triangular(double min,
 double max,
 double left,
 double mode,
 double right)
Generates a sample of truncated Triangular distribution.
Distribution triangular(left, right, mode) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see triangular(double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
left - the minimum x value for triangular distribution.
mode - the most likely x value for triangular distribution.
right - the maximum x value for triangular distribution.
Returns:
the generated sample

triangular

static double triangular(double min,
 double max,
 double mode,
 Random r)
Generates a sample of the Triangular distribution using the specified random number generator. For more details see triangular(double,double,double).
Parameters:
min - the minimum x value.
max - the maximum x value.
mode - the most likely x value.
r - the random number generator.
Returns:
the generated sample.

triangular

static double triangular(double min,
 double max,
 double left,
 double mode,
 double right,
 Random r)
Generates a sample of truncated Triangular distribution using the specified random number generator.
Distribution triangular(left, right, mode) is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see triangular(double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
left - the minimum x value for triangular distribution.
mode - the most likely x value for triangular distribution.
right - the maximum x value for triangular distribution.
r - the random number generator.
Returns:
the generated sample

weibull

default double weibull(double beta,
 double alpha)
Generates a sample of the Weibull distribution with min set to 0. Is equivalent to weibull(alpha, beta, 0). For more details see weibull(double,double,double).
Parameters:
beta - the scale parameter > 0.
alpha - the shape parameter > 0.
Returns:
the generated sample.

weibull

default double weibull(double alpha,
 double beta,
 double min)
Generates a sample of the Weibull distribution.

The Weibull distribution is a continuous distribution bounded on the lower side. Because it provides one of the limiting distributions for extreme values, it is also referred to as the Frechet distribution and the Weibull-Gnedenko distribution.

Like the Gamma distribution, it has three distinct regions. For alpha=1, beta=1/lambda the Weibull distribution is reduced to the Exponential distribution, starting at a finite value at minimum x and decreasing monotonically thereafter. For alpha<1, the Weibull distribution tends to infinity at minimum x and decreases monotonically for increasing x. for alpha>1, the Weibull distribution is 0 at minimum x, peaks at a value that depends on both alpha and beta, decreasing monotonically thereafter. Uniquely, the Weibull distribution has negative skewness for alpha>3.6.

The Weibull distribution can also be used to approximate the Normal distribution for alpha=3.6, while maintaining its strictly positive values of x [actually (x-min)], although the kurtosis is slightly smaller than 3, the Normal value.

The Weibull distribution derived its popularity from its use to model the strength of materials, and has since been used to model just about everything. In particular, the Weibull distribution is used to represent wearout lifetimes in reliability, wind speed, rainfall intensity, health related issues, germination, duration of industrial stoppages, migratory systems, and thunderstorm data.

Parameters:
alpha - the shape parameter > 0.
beta - the scale parameter > 0.
min - the minimum x value.
Returns:
the generated sample.

weibull

default double weibull(double min,
 double max,
 double alpha,
 double shift,
 double stretch)
Generates a sample of truncated Weibull distribution.
Distribution weibull(alpha, stretch, 0) is shifted to the right by shift and then truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see weibull(double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
alpha - the shape parameter > 0.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the scale parameter.
Returns:
the generated sample

weibull

static double weibull(double alpha,
 double beta,
 double min,
 Random r)
Generates a sample of the Weibull distribution using the specified random number generator. For more details see weibull(double,double,double).
Parameters:
alpha - the shape parameter > 0.
beta - the scale parameter > 0.
min - the minimum x value.
r - the random number generator.
Returns:
the generated sample.

weibull

static double weibull(double min,
 double max,
 double alpha,
 double shift,
 double stretch,
 Random r)
Generates a sample of truncated Weibull distribution using the specified random number generator.
Distribution weibull(alpha, stretch, 0) is shifted to the right by shift and then truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see weibull(double, double, double)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
alpha - the shape parameter > 0.
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the scale parameter.
r - the random number generator.
Returns:
the generated sample