SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.rng.RandomStreamBase Class Referenceabstract

This class provides a convenient foundation on which RNGs can be built. More...

Inheritance diagram for umontreal.ssj.rng.RandomStreamBase:
umontreal.ssj.rng.CloneableRandomStream umontreal.ssj.rng.RandomStream umontreal.ssj.mcqmctools.anova.SplitStream umontreal.ssj.rng.LFSR113 umontreal.ssj.rng.LFSR258 umontreal.ssj.rng.MRG31k3p umontreal.ssj.rng.MRG32k3a umontreal.ssj.rng.MRG32k3aL umontreal.ssj.rng.WELL512

Public Member Functions

abstract void resetStartStream ()
 Reinitializes the stream to its initial state \(I_g\): \(C_g\) and \(B_g\) are set to \(I_g\).
abstract void resetStartSubstream ()
 Reinitializes the stream to the beginning of its current substream:
abstract void resetNextSubstream ()
 Reinitializes the stream to the beginning of its next substream:
abstract String toString ()
 Returns a string containing the current state of this stream.
void increasedPrecision (boolean incp)
 After calling this method with incp = true, each call to the RNG (direct or indirect) for this stream will return a uniform random number with more bits of precision than what is returned by nextValue, and will advance the state of the stream by 2 steps instead of 1 (i.e., nextValue will be called twice for each random number).
double nextDouble ()
 Returns a uniform random number between 0 and 1 from the stream.
void nextArrayOfDouble (double[] u, int start, int n)
 Calls nextDouble n times to fill the array u.
int nextInt (int i, int j)
 Calls nextDouble once to create one integer between i and j.
void nextArrayOfInt (int i, int j, int[] u, int start, int n)
 Calls nextInt n times to fill the array u.
String formatState ()
 Use the toString method.
String formatStateFull ()
 Use the toStringFull method.
RandomStreamBase clone ()
 Clones the current generator and return its copy.

Protected Member Functions

abstract double nextValue ()
 This method should return the next random number (between 0 and 1) from the current stream.

Detailed Description

This class provides a convenient foundation on which RNGs can be built.

It implements all the methods which do not depend directly on the generator itself, but only on its output, which is to be defined by implementing the abstract method nextValue. In the present class, all methods returning random numbers directly or indirectly (nextDouble, nextArrayOfDouble, nextInt and nextArrayOfInt) call nextValue. Thus, to define a subclass that implements a RNG, it suffices to implement nextValue, in addition to the reset... and toString methods. Of course, the other methods may also be overridden for improved efficiency.

If the nextValue already generates numbers with a precision of 53-bits or higher, then nextDouble can be overridden to improve the performance. The mechanism for increasing the precision assumes that nextValue returns at least 29 bits of precision, in which case the higher precision numbers will have roughly 52 bits of precision. This mechanism was designed primarily for RNGs that return numbers with around 30 to 32 bits of precision.

RandomStreamBase and its subclasses are implementing the Serializable interface. Each class has a serial number wich represent the class version. For instance 70510 means that the last change was the 10th May 2007.

Definition at line 54 of file RandomStreamBase.java.

Member Function Documentation

◆ clone()

RandomStreamBase umontreal.ssj.rng.RandomStreamBase.clone ( )

Clones the current generator and return its copy.

Returns
A deep copy of the current generator

Implements umontreal.ssj.rng.CloneableRandomStream.

Reimplemented in umontreal.ssj.mcqmctools.anova.SplitStream, umontreal.ssj.rng.LFSR113, umontreal.ssj.rng.LFSR258, umontreal.ssj.rng.MRG31k3p, umontreal.ssj.rng.MRG32k3a, umontreal.ssj.rng.MRG32k3aL, and umontreal.ssj.rng.WELL512.

Definition at line 210 of file RandomStreamBase.java.

◆ formatState()

String umontreal.ssj.rng.RandomStreamBase.formatState ( )

Use the toString method.

Definition at line 193 of file RandomStreamBase.java.

◆ formatStateFull()

String umontreal.ssj.rng.RandomStreamBase.formatStateFull ( )

Use the toStringFull method.

Definition at line 201 of file RandomStreamBase.java.

◆ increasedPrecision()

void umontreal.ssj.rng.RandomStreamBase.increasedPrecision ( boolean incp)

After calling this method with incp = true, each call to the RNG (direct or indirect) for this stream will return a uniform random number with more bits of precision than what is returned by nextValue, and will advance the state of the stream by 2 steps instead of 1 (i.e., nextValue will be called twice for each random number).

More precisely, if s is a stream of a subclass of RandomStreamBase, when the precision has been increased, the instruction "<tt>u = s.nextDouble()</tt>", is equivalent to "<tt>u = (s.nextValue() + s.nextValue()*fact) % 1.0</tt>" where the constant fact is equal to \(2^{-24}\). This also applies when calling nextDouble indirectly (e.g., via nextInt, etc.). By default, or if this method is called again with incp = false, each call to nextDouble for this stream advances the state by 1 step and returns the same number as nextValue.

Parameters
incpif the generator will be set to high precision mode

Definition at line 95 of file RandomStreamBase.java.

◆ nextArrayOfDouble()

void umontreal.ssj.rng.RandomStreamBase.nextArrayOfDouble ( double[] u,
int start,
int n )

Calls nextDouble n times to fill the array u.

Parameters
uthe array in which the numbers will be stored
startthe first index of u to be used
nthe number of random numbers to put in u

Implements umontreal.ssj.rng.RandomStream.

Definition at line 134 of file RandomStreamBase.java.

◆ nextArrayOfInt()

void umontreal.ssj.rng.RandomStreamBase.nextArrayOfInt ( int i,
int j,
int[] u,
int start,
int n )

Calls nextInt n times to fill the array u.

This method should be overridden if a faster implementation exists for the specific generator.

Parameters
ithe smallest possible integer to put in u
jthe largest possible integer to put in u
uthe array in which the numbers will be stored
startthe first index of u to be used
nthe number of random numbers to put in u

Implements umontreal.ssj.rng.RandomStream.

Definition at line 175 of file RandomStreamBase.java.

◆ nextDouble()

double umontreal.ssj.rng.RandomStreamBase.nextDouble ( )

Returns a uniform random number between 0 and 1 from the stream.

Its behavior depends on the last call to increasedPrecision. The generators programmed in SSJ never return the values 0 or 1.

Returns
a number in the interval (0,1)

Implements umontreal.ssj.rng.RandomStream.

Definition at line 117 of file RandomStreamBase.java.

◆ nextInt()

int umontreal.ssj.rng.RandomStreamBase.nextInt ( int i,
int j )

Calls nextDouble once to create one integer between i and j.

This method always uses the highest order bits of the random number. It should be overridden if a faster implementation exists for the specific generator.

Parameters
ithe smallest possible returned integer
jthe largest possible returned integer
Returns
a random integer between i and j

Implements umontreal.ssj.rng.RandomStream.

Reimplemented in umontreal.ssj.rng.LFSR113, and umontreal.ssj.rng.LFSR258.

Definition at line 157 of file RandomStreamBase.java.

◆ nextValue()

abstract double umontreal.ssj.rng.RandomStreamBase.nextValue ( )
abstractprotected

This method should return the next random number (between 0 and 1) from the current stream.

If the stream is set to the high precision mode (increasedPrecision(true) was called), then each call to nextDouble will call nextValue twice, otherwise it will call it only once.

Returns
a number in the interval (0,1)

Reimplemented in umontreal.ssj.mcqmctools.anova.SplitStream, umontreal.ssj.rng.LFSR113, umontreal.ssj.rng.LFSR258, umontreal.ssj.rng.MRG31k3p, umontreal.ssj.rng.MRG32k3a, umontreal.ssj.rng.MRG32k3aL, and umontreal.ssj.rng.WELL512.

◆ resetNextSubstream()

abstract void umontreal.ssj.rng.RandomStreamBase.resetNextSubstream ( )
abstract

Reinitializes the stream to the beginning of its next substream:

\(N_g\) is computed, and \(C_g\) and \(B_g\) are set to \(N_g\).

Implements umontreal.ssj.rng.RandomStream.

Reimplemented in umontreal.ssj.mcqmctools.anova.SplitStream, umontreal.ssj.rng.LFSR113, umontreal.ssj.rng.LFSR258, umontreal.ssj.rng.MRG31k3p, umontreal.ssj.rng.MRG32k3a, umontreal.ssj.rng.MRG32k3aL, and umontreal.ssj.rng.WELL512.

◆ resetStartStream()

abstract void umontreal.ssj.rng.RandomStreamBase.resetStartStream ( )
abstract

◆ resetStartSubstream()

abstract void umontreal.ssj.rng.RandomStreamBase.resetStartSubstream ( )
abstract

◆ toString()

abstract String umontreal.ssj.rng.RandomStreamBase.toString ( )
abstract

Returns a string containing the current state of this stream.

Returns
the state of the generator formated as a string

Implements umontreal.ssj.rng.RandomStream.

Reimplemented in umontreal.ssj.mcqmctools.anova.SplitStream, umontreal.ssj.rng.LFSR113, umontreal.ssj.rng.LFSR258, umontreal.ssj.rng.MRG31k3p, umontreal.ssj.rng.MRG32k3a, umontreal.ssj.rng.MRG32k3aL, and umontreal.ssj.rng.WELL512.


The documentation for this class was generated from the following file: