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

    Constructors
    Constructor
    Description
    Creates a new instance of random number generator with the specified integer seed.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the underlying instance of Random wrapped by this class.
    double
     
    double
    normal(double mean, double sd)
    Returns the next pseudorandom number normally distributed with the specified mead and standard deviation.
    <T> T
    randomOf(List<? extends T> list)
    Returns a randomly selected element from the specified list.
    <T> T
    randomOf(T... values)
    Returns a randomly selected element from the specified elements.
    void
    setSeed(long seed)
     
    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.
    double
    uniform(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      nextDouble in interface org.apache.commons.math3.random.RandomGenerator
      Specified by:
      nextDouble in class org.apache.commons.math3.random.AbstractRandomGenerator
    • setSeed

      public void setSeed(long seed)
      Specified by:
      setSeed in interface org.apache.commons.math3.random.RandomGenerator
      Specified by:
      setSeed in class org.apache.commons.math3.random.AbstractRandomGenerator
    • getRandom

      public Random getRandom()
      Returns the underlying instance of Random wrapped 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 distribution
      max - 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 distribution
      mode - mode of the triangular distribution
      max - 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 distribution
      sd - standard deviation of the normal distribution
      Returns:
      next pseudorandom double number
    • randomOf

      public <T> T randomOf(List<? extends T> list)
      Returns a randomly selected element from the specified list. All elements have equal probability of selection. If the specified list is empty, returns null.
      Type Parameters:
      T - type of elements
      Parameters:
      list - specified list
      Returns:
      randomly selected element from the specified list, or null if 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, returns null.
      Type Parameters:
      T - type of elements
      Parameters:
      values - specified elements
      Returns:
      randomly selected element from the specified list, or null if the specified array of elements is empty