Class RNGDistribution
- Direct Known Subclasses:
RNGDistribution.Binomial,RNGDistribution.Exponential,RNGDistribution.Geometric,RNGDistribution.Gillespie,RNGDistribution.Normal,RNGDistribution.Uniform
Currently available random number distributions:
- Uniform:
- Uniformly distributed random numbers with support
[min, max). - Exponential:
- Exponentially distributed random numbers with support
[0.0,Double.MAX_VALUE) - Normal:
- Normally (or Gaussian) distributed random numbers with support
(-.Double.MAX_VALUE,Double.MAX_VALUE) - Geometric:
- Geometrically distributed random numbers with support
{1,2,3,...}. - Binomial:
- Binomially distributed random numbers with support
{0,1,2,3,...}.
Note: in order to permit 100% reproducible results it is
essential that all models must share a single instance of the random
number generator (RNG). By the same token, GUI methods that require random
numbers (e.g. for laying out networks) must use a different instance
of the RNG. If an initial seed was set for the models' RNG then
it is recommended that a reproducible seed (the same seed) is also set for
the RNG used by the GUI. This ensures that e.g. identical layouts can be
re-generated while not interfering with the model calculations.
- Author:
- Christoph Hauert
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBinomially distributed random numbers with support{0,1,2,3,..., n}.static classExponentially distributed random numbers with support[0.0,.Double.MAX_VALUE)static classGeometrically distributed random numbers with support{1,2,3,...}.static classGillespie algorithm for selecting integers with support{0,1,2,3,..., n}but with different weights.static classNormally (or Gaussian) distributed random numbers with support(-.Double.MAX_VALUE,Double.MAX_VALUE)static interfaceThe interface to execute commands in a manner that is agnostic to the implementation details regarding GWT or JRE environments.static classUniformly distributed random numbers with support[min, max). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MersenneTwisterReference to theMersenneTwisterthat supplies the random numbers for the different distributions.protected longSeed for random number generator.protected booleantrueif seed was set.protected intnumber of samples for tests. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate new random number distribution usingrngas the random number generator. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear seed for random number generator.abstract RNGDistributionclone()Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.protected voidclone(RNGDistribution clone) Copy settings ofthistoclone.getRNG()Get random number generator of this distribution.longRetrieve seed of random number generator in[0, 233-1].booleanCheck if seed of random number generator has been set.booleanUniformly distributed random boolean.bytenextByte()Uniformly distributed random byte in[0,.Byte.MAX_VALUE)voidnextBytes(byte[] bytes) Fill byte arraybyteswith uniformly distributed random bytes in[0,.Byte.MAX_VALUE)doubleUniformly distributed random number from interval[0, 1)with regular precision (based on 31bit random integer).doubleGaussian distributed random number with mean0and variance1(standard Normal distribution) with regular precision (based on 31bit random integer).intnextInt()Uniformly distributed random integer in[0,.Integer.MAX_VALUE)intnextInt(int n) Uniformly distributed random integer in[0, n).doublerandom01()Uniformly distributed random number from interval[0, 1)with regular precision (based on 31bit random integer).doubleUniformly distributed random number from interval [0, 1) with high precision (based on 53bit random integer).intrandom0n(int n) Uniformly distributed integer random number from interval[0, n).intrandom0N(int n) Uniformly distributed integer random number from interval[0, n].voidsetRNG(MersenneTwister rng) Set custom random number generatorrngof this distribution.voidPass seed to random number generator.voidsetRNGSeed(long seed) Set seed of random number generator toseed.
-
Field Details
-
rng
Reference to theMersenneTwisterthat supplies the random numbers for the different distributions. -
seed
protected long seedSeed for random number generator. -
seedSet
protected boolean seedSettrueif seed was set. -
testSamples
protected int testSamplesnumber of samples for tests.
-
-
Constructor Details
-
RNGDistribution
Create new random number distribution usingrngas the random number generator. Ifrng==nulla new instance of theMersenneTwisterrandom number generator is assigned to distribution.Protected default constructor to ensure non-instantiability.
- Parameters:
rng- random number generator
-
-
Method Details
-
setRNG
Set custom random number generatorrngof this distribution.- Parameters:
rng- random number generator
-
getRNG
Get random number generator of this distribution.- Returns:
- random number generator of distribution
-
random01
public double random01()Uniformly distributed random number from interval[0, 1)with regular precision (based on 31bit random integer).- Returns:
- random number in
[0, 1) - See Also:
-
random01d
public double random01d()Uniformly distributed random number from interval [0, 1) with high precision (based on 53bit random integer).- Returns:
- high precision random number in
[0, 1) - See Also:
-
random0N
public int random0N(int n) Uniformly distributed integer random number from interval[0, n].- Parameters:
n- upper bound (inclusive)- Returns:
- random integer in
[0, n] - See Also:
-
random0n
public int random0n(int n) Uniformly distributed integer random number from interval[0, n).- Parameters:
n- integer upper bound (exclusive)- Returns:
- random integer in
[0, n) - See Also:
-
nextInt
public int nextInt()Uniformly distributed random integer in[0,.Integer.MAX_VALUE)Note: compatibility method with
Random.- Returns:
- random integer in
[0,Integer.MAX_VALUE) - See Also:
-
nextInt
public int nextInt(int n) Uniformly distributed random integer in[0, n).Note: compatibility method with
Random.- Parameters:
n- integer upper bound (exclusive)- Returns:
- random integer in
[0, n) - See Also:
-
nextByte
public byte nextByte()Uniformly distributed random byte in[0,.Byte.MAX_VALUE)Note: compatibility method with
Random.- Returns:
- random byte in
[0, 127] - See Also:
-
nextBytes
public void nextBytes(byte[] bytes) Fill byte arraybyteswith uniformly distributed random bytes in[0,.Byte.MAX_VALUE)Note: compatibility method with
Random.- Parameters:
bytes- array to fill with uniformly distributed random bytes in[0, 127]- See Also:
-
nextBoolean
public boolean nextBoolean()Uniformly distributed random boolean.Note: compatibility method with
Random.- Returns:
truewith probability0.5- See Also:
-
nextDouble
public double nextDouble()Uniformly distributed random number from interval[0, 1)with regular precision (based on 31bit random integer).- Returns:
- random number in
[0, 1) - See Also:
-
nextGaussian
public double nextGaussian()Gaussian distributed random number with mean0and variance1(standard Normal distribution) with regular precision (based on 31bit random integer).- Returns:
- random number in
(-Double.MAX_VALUE , Double.MAX_VALUE) - See Also:
-
setRNGSeed
public void setRNGSeed(long seed) Set seed of random number generator toseed. Since MersenneTwister only uses lower 32bits of long,seedis truncated accordingly to fall in interval[0, 233-1].- Parameters:
seed- for random number generator- See Also:
-
setRNGSeed
public void setRNGSeed()Pass seed to random number generator.- See Also:
-
getRNGSeed
public long getRNGSeed()Retrieve seed of random number generator in[0, 233-1]. If no seed has been set, return-1L.- Returns:
- seed of random number generator or
-1Lif seed has not been set
-
clearRNGSeed
public void clearRNGSeed()Clear seed for random number generator. -
isRNGSeedSet
public boolean isRNGSeedSet()Check if seed of random number generator has been set.- Returns:
trueif seed set
-
clone
Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.IMPORTANT:
-
clone
Copy settings ofthistoclone.- Parameters:
clone- clonedRNGDistribution
-