Class DefaultRandomGenerator
java.lang.Object
org.apache.commons.math3.random.AbstractRandomGenerator
com.amalgamasimulation.utils.random.DefaultRandomGenerator
- All Implemented Interfaces:
org.apache.commons.math3.random.RandomGenerator
public class DefaultRandomGenerator
extends org.apache.commons.math3.random.AbstractRandomGenerator
Convenience class that allows developers to easily create an instance of
AbstractRandomGenerator by specifying the seed.
Uses the underlying instance of standard JDK's Random class.
- Author:
- Andrey Malykhanov
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultRandomGenerator(int seed) Creates a new instance of random number generator with the specified integer seed. -
Method Summary
Modifier and TypeMethodDescriptionReturns the underlying instance ofRandomwrapped by this class.doubledoublenormal(double mean, double sd) Returns the next pseudorandom number normally distributed with the specified mead and standard deviation.<T> TReturns a randomly selected element from the specified list.<T> TrandomOf(T... values) Returns a randomly selected element from the specified elements.voidsetSeed(long seed) doubletriangular(double min, double mode, double max) Returns the next pseudorandom number distributed according to a triangular distribution with the specified min, mode and max values.doubleuniform(double min, double max) Returns the next pseudorandom number uniformly distributed between the specified min and max values.Methods inherited from class org.apache.commons.math3.random.AbstractRandomGenerator
clear, nextBoolean, nextBytes, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed, setSeed
-
Constructor Details
-
DefaultRandomGenerator
public DefaultRandomGenerator(int seed) Creates a new instance of random number generator with the specified integer seed.- Parameters:
seed- specified seed
-
-
Method Details
-
nextDouble
public double nextDouble()- Specified by:
nextDoublein interfaceorg.apache.commons.math3.random.RandomGenerator- Specified by:
nextDoublein classorg.apache.commons.math3.random.AbstractRandomGenerator
-
setSeed
public void setSeed(long seed) - Specified by:
setSeedin interfaceorg.apache.commons.math3.random.RandomGenerator- Specified by:
setSeedin classorg.apache.commons.math3.random.AbstractRandomGenerator
-
getRandom
Returns the underlying instance ofRandomwrapped by this class.- Returns:
- underlying instance of
Random
-
uniform
public double uniform(double min, double max) Returns the next pseudorandom number uniformly distributed between the specified min and max values.- Parameters:
min- minimum value of the distributionmax- maximum value of the distribution- Returns:
- next pseudorandom double number
-
triangular
public double triangular(double min, double mode, double max) Returns the next pseudorandom number distributed according to a triangular distribution with the specified min, mode and max values.- Parameters:
min- minimum value of the triangular distributionmode- mode of the triangular distributionmax- maximum value of the triangular distribution- Returns:
- next pseudorandom double number
-
normal
public double normal(double mean, double sd) Returns the next pseudorandom number normally distributed with the specified mead and standard deviation.- Parameters:
mean- mean value of the normal distributionsd- standard deviation of the normal distribution- Returns:
- next pseudorandom double number
-
randomOf
Returns a randomly selected element from the specified list. All elements have equal probability of selection. If the specified list is empty, returnsnull.- Type Parameters:
T- type of elements- Parameters:
list- specified list- Returns:
- randomly selected element from the specified list, or
nullif the list is empty
-
randomOf
public <T> T randomOf(T... values) Returns a randomly selected element from the specified elements. All elements have equal probability of selection. If the specified array of elements is empty, returnsnull.- Type Parameters:
T- type of elements- Parameters:
values- specified elements- Returns:
- randomly selected element from the specified list, or
nullif the specified array of elements is empty
-