Class RNStreamFactory

  • All Implemented Interfaces:
    GetNameIfc, IdentityIfc

    public class RNStreamFactory
    extends Identity
    An update (as of Jan-17-2021) of the MRG32k3a class from:

    https://github.com/umontreal-simul/ssj package umontreal.ssj.rng.MRG32k3a

    This representation fits the stream architecture facilitated by the JSL and (importantly) allows multiple instances of the factory to be instantiated. This allows streams from different factories to produce the same streams and underlying random numbers.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  RNStreamFactory.RNStream
      Instances of RNStream are what is made by the factory.
    • Constructor Summary

      Constructors 
      Constructor Description
      RNStreamFactory()
      Creates a factory with no name
      RNStreamFactory​(java.lang.String name)
      Creates a factory with the provided name
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void advanceSeeds​(int n)
      Advances the seeds n times.
      static boolean checkSeed​(long[] seed)
      Use to check seeds to see if they are valid for the factory
      static RNStreamFactory getDefaultFactory()
      Returns a reference to a "global" stream factory
      long[] getDefaultInitialFactorySeed()
      Gets the default initial package seed: seed = {12345, 12345, 12345, 12345, 12345, 12345};
      long[] getFactorySeed()
      Returns the current factory seed
      RNStreamIfc getStream()
      Tells the factory to make and return a RNStream
      RNStreamIfc getStream​(java.lang.String name)
      Tells the provider to make and return a RNStream with the provided name
      RNStreamFactory newInstance()
      Returns a clone of the factory that will produce exactly the same streams.
      RNStreamFactory newInstance​(java.lang.String name)
      Returns a new instance of the factory that will produce exactly the same streams The state of the returned factory will be exactly the same as the current factory.
      void resetFactorySeed()
      Resets the package seed to the default initial package seed: seed = {12345, 12345, 12345, 12345, 12345, 12345};
      static void setDefaultFactory​(RNStreamFactory f)
      Sets the default factory to the supplied factory
      void setFactorySeed​(long[] seed)
      Sets the initial seed to the six integers in the vector seed[0..5].
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RNStreamFactory

        public RNStreamFactory()
        Creates a factory with no name
      • RNStreamFactory

        public RNStreamFactory​(java.lang.String name)
        Creates a factory with the provided name
        Parameters:
        name - a name for the factory, may be null
    • Method Detail

      • checkSeed

        public static boolean checkSeed​(long[] seed)
        Use to check seeds to see if they are valid for the factory
        Parameters:
        seed - the seed to check
        Returns:
        true if the supplied seed can be used, false otherwise
      • newInstance

        public RNStreamFactory newInstance()
        Returns a clone of the factory that will produce exactly the same streams. The state of the returned factory will be exactly the same as the current factory.
        Returns:
        new instance of the factory
      • newInstance

        public RNStreamFactory newInstance​(java.lang.String name)
        Returns a new instance of the factory that will produce exactly the same streams The state of the returned factory will be exactly the same as the current factory.
        Parameters:
        name - the name for the factory, may be null
        Returns:
        the new instance of the factory
      • getDefaultFactory

        public static RNStreamFactory getDefaultFactory()
        Returns a reference to a "global" stream factory
        Returns:
        a reference to a "global" stream factory
      • setDefaultFactory

        public static void setDefaultFactory​(RNStreamFactory f)
        Sets the default factory to the supplied factory
        Parameters:
        f - must not be null
      • getDefaultInitialFactorySeed

        public final long[] getDefaultInitialFactorySeed()
        Gets the default initial package seed: seed = {12345, 12345, 12345, 12345, 12345, 12345};
        Returns:
        an array holding the initial seed values
      • getFactorySeed

        public final long[] getFactorySeed()
        Returns the current factory seed
        Returns:
        the array of seed values for the current state
      • setFactorySeed

        public final void setFactorySeed​(long[] seed)
        Sets the initial seed to the six integers in the vector seed[0..5]. This will be the seed (initial state) of the first stream. By default, this seed is (12345, 12345, 12345, 12345, 12345, 12345).

        If it is called, the first 3 values of the seed must all be less than m1 = 4294967087, and not all 0; and the last 3 values must all be less than m2 = 4294944443, and not all 0. Throws illegal argument exception for invalid seeds

        Parameters:
        seed - the seeds
      • resetFactorySeed

        public final void resetFactorySeed()
        Resets the package seed to the default initial package seed: seed = {12345, 12345, 12345, 12345, 12345, 12345};
      • advanceSeeds

        public final void advanceSeeds​(int n)
        Advances the seeds n times. Acts as if n streams were created, without actually creating the streams. The seeds will be advanced 2^127 steps
        Parameters:
        n - the number of times to advance
      • getStream

        public final RNStreamIfc getStream​(java.lang.String name)
        Tells the provider to make and return a RNStream with the provided name
        Parameters:
        name - can be null
        Returns:
        the made stream
      • getStream

        public final RNStreamIfc getStream()
        Tells the factory to make and return a RNStream
        Returns:
        the made stream