Package util

Record Class Randomness

Record Components:
seed - The seed of this source of randomness. Values derived from this source are deterministic for a given seed and ID.

public record Randomness(long seed) extends Record
Provides random number generator seeds to support reproducible randomness that is robust to different compositions of submodels with unique string identifiers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final long
    The field for the seed record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Randomness(long seed)
    Creates an instance of a Randomness record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    Return a random number generator to be used by a submodel with ID `id`.
    final int
    Returns a hash code value for this object.
    Return a new source of randomness that is next (after this one) in a deterministic sequence of randomness sources.
    Return a new source of randomness to be used by a submodel with ID `id`.
    long
    Returns the value of the seed record component.
    long
    Return an RNG seed to be used by a submodel with ID `id`.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • seed

      private final long seed
      The field for the seed record component.
  • Constructor Details

    • Randomness

      public Randomness(long seed)
      Creates an instance of a Randomness record class.
      Parameters:
      seed - the value for the seed record component
  • Method Details

    • next

      public Randomness next()
      Return a new source of randomness that is next (after this one) in a deterministic sequence of randomness sources. This should only be called once on a source, as returned values are identical. This is useful for programs that want to run a sequence of independent simulations that is reproducible from a single initial seed.
    • randomnessFor

      public Randomness randomnessFor(String id)
      Return a new source of randomness to be used by a submodel with ID `id`. This facilitates hierarchical submodels.
    • seedFor

      public long seedFor(String id)
      Return an RNG seed to be used by a submodel with ID `id`.
    • generatorFor

      public Random generatorFor(String id)
      Return a random number generator to be used by a submodel with ID `id`.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • seed

      public long seed()
      Returns the value of the seed record component.
      Returns:
      the value of the seed record component