Class RNStreamProvider

  • All Implemented Interfaces:
    RNStreamProviderIfc

    public final class RNStreamProvider
    extends java.lang.Object
    implements RNStreamProviderIfc
    A concrete implementation of RNStreamProviderIfc. If more than getStreamNumberWarningLimit() streams are made a warning message is logged. Generally, unless you know what you are doing you should not need an immense number of streams. Instead, use a small number of streams many times. Conceptually this provider could have a possibly infinite number of streams, which would have bad memory implications. Thus, the reason for the warning. The default stream if not set is the first stream.
    • Constructor Detail

      • RNStreamProvider

        public RNStreamProvider()
        Assumes stream 1 is the default
      • RNStreamProvider

        public RNStreamProvider​(int defaultStreamNum)
        Parameters:
        defaultStreamNum - the stream number to use as the default
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getStreamNumberWarningLimit

        public final int getStreamNumberWarningLimit()
        Returns:
        the limit associated with the warning message concerning the number of streams created
      • setStreamNumberWarningLimit

        public final void setStreamNumberWarningLimit​(int limit)
        Parameters:
        limit - the limit associated with the warning message concerning the number of streams created
      • defaultRNStreamNumber

        public int defaultRNStreamNumber()
        Description copied from interface: RNStreamProviderIfc
        The sequence number associated with the default random number stream. This allows clients to know what stream number has been assigned to the default.
        Specified by:
        defaultRNStreamNumber in interface RNStreamProviderIfc
        Returns:
        the stream number of the default random number stream for this provider
      • lastRNStreamNumber

        public int lastRNStreamNumber()
        Description copied from interface: RNStreamProviderIfc
        Each call to nextStream() makes another stream in the sequence of streams. This method should return the number of streams provided by the provider. If nextStream() is called once, then lastRNStreamNumber() should return 1. If nextStream() is called twice then lastRNStreamNumber() should return 2, etc. Thus, this method returns the number in the sequence associated with the last stream made. If lastRNStreamNumber() returns 0, then no streams have been provided.
        Specified by:
        lastRNStreamNumber in interface RNStreamProviderIfc
        Returns:
        the number in the sequence associated with the last stream made
      • rnStream

        public RNStreamIfc rnStream​(int i)
        Description copied from interface: RNStreamProviderIfc
        Tells the provider to return the ith stream of the sequence of streams that it provides. If i is greater than lastRNStreamNumber() then lastRNStreamNumber() is advanced according to the additional number of streams. For example, if lastRNStreamNumber() = 10 and i = 15, then streams 11, 12, 13, 14, 15 are assumed provided and stream 15 is returned and lastRNStreamNumber() now equals 15. If i is less than or equal to lastRNStreamNumber(), then no new streams are created, lastRNStreamNumber() stays at its current value and the ith stream is returned.
        Specified by:
        rnStream in interface RNStreamProviderIfc
        Parameters:
        i - the ith stream in the sequence of provided streams, must be 1, 2, 3 ...
        Returns:
        the ith RNStreamIfc provided in the sequence of streams
      • getStreamNumber

        public int getStreamNumber​(RNStreamIfc stream)
        Specified by:
        getStreamNumber in interface RNStreamProviderIfc
        Parameters:
        stream - the stream to find the number for
        Returns:
        the stream number of the stream for this provider or -1 if the stream has not been provided by this provider. Valid stream numbers start at 1.
      • advanceStreamMechanism

        public void advanceStreamMechanism​(int n)
        Description copied from interface: RNStreamProviderIfc
        Advances the state of the provider through n streams. Acts as if n streams were created, without actually creating the streams. lastRNStreamNumber() remains the same after calling this method. In other words, this method should act as if nextRNStream() was not called but advance the underlying stream mechanism as if n streams had been provided.
        Specified by:
        advanceStreamMechanism in interface RNStreamProviderIfc
        Parameters:
        n - the number of times to advance
      • resetRNStreamSequence

        public void resetRNStreamSequence()
        Description copied from interface: RNStreamProviderIfc
        Causes the provider to act as if it has never created any streams. Thus, the next call to nextRNStream() after the reset should return the 1st stream in the sequence of streams that this provider would normally provide in the order in which they would be provided.
        Specified by:
        resetRNStreamSequence in interface RNStreamProviderIfc
      • getDefaultInitialSeed

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

        public final long[] getCurrentSeed()
        Returns the current seed
        Returns:
        the array of seed values for the current state
      • setInitialSeed

        public final void setInitialSeed​(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. Returns false for invalid seeds, and true otherwise.

        Parameters:
        seed - the seeds