SSJ  3.3.1
Stochastic Simulation in Java
Public Member Functions | Static Public Member Functions | List of all members
RandMrg Class Reference

USE MRG32k3a INSTEAD of this class. More...

Inheritance diagram for RandMrg:
[legend]
Collaboration diagram for RandMrg:
[legend]

Public Member Functions

 RandMrg ()
 Constructs a new stream, initializes its seed \(I_g\), sets \(B_g\) and \(C_g\) equal to \(I_g\), and sets its antithetic switch to false. More...
 
 RandMrg (String name)
 Constructs a new stream with an identifier name (can be used when printing the stream state, in error messages, etc.). More...
 
void resetStartStream ()
 Reinitializes the stream to its initial state \(I_g\): \(C_g\) and \(B_g\) are set to \(I_g\).
 
void resetStartSubstream ()
 Reinitializes the stream to the beginning of its current substream: \(C_g\) is set to \(B_g\).
 
void resetNextSubstream ()
 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\).
 
void increasedPrecis (boolean incp)
 After calling this method with incp = true, each call to the generator (direct or indirect) for this stream will return a uniform random number with (roughly) 53 bits of resolution instead of 32 bits, and will advance the state of the stream by 2 steps instead of. More...
 
void setAntithetic (boolean anti)
 
void advanceState (int e, int c)
 Advances the state of this stream by \(k\) values, without modifying the states of other streams (as in setSeed), nor the values of \(B_g\) and \(I_g\) associated with this stream. More...
 
void setSeed (long seed[])
 Sets the initial seed \(I_g\) of this stream to the vector seed[0..5]. More...
 
double [] getState ()
 Returns the current state \(C_g\) of this stream. More...
 
String toString ()
 Returns a string containing the current state of this stream. More...
 
String toStringFull ()
 Returns a string containing the name of this stream and the values of all its internal variables. More...
 
double nextDouble ()
 Returns a (pseudo)random number from the uniform distribution over the interval \((0,1)\), using this stream, after advancing its state by one step. More...
 
void nextArrayOfDouble (double[] u, int start, int n)
 Generates n (pseudo)random numbers from the uniform distribution and stores them into the array u starting at index start. More...
 
int nextInt (int i, int j)
 Returns a (pseudo)random number from the discrete uniform distribution over the integers \(\{i,i+1,…,j\}\), using this stream. More...
 
void nextArrayOfInt (int i, int j, int[] u, int start, int n)
 Generates n (pseudo)random numbers from the discrete uniform distribution over the integers \(\{i,i+1,…,j\}\), using this stream and stores the result in the array u starting at index start. More...
 
RandMrg clone ()
 Clones the current generator and return its copy. More...
 

Static Public Member Functions

static void setPackageSeed (long seed[])
 Sets the initial seed for the class RandMrg to the six integers in the vector seed[0..5]. More...
 

Detailed Description

USE MRG32k3a INSTEAD of this class.

This class implements the interface RandomStream directly, with a few additional tools. It uses the same backbone (or main) generator as MRG32k3a, but it is an older implementation that does not extend RandomStreamBase, and it is about 10% slower.

Constructor & Destructor Documentation

◆ RandMrg() [1/2]

RandMrg ( )

Constructs a new stream, initializes its seed \(I_g\), sets \(B_g\) and \(C_g\) equal to \(I_g\), and sets its antithetic switch to false.

The seed \(I_g\) is equal to the initial seed of the package given by setPackageSeed(long[]) if this is the first stream created, otherwise it is \(Z\) steps ahead of that of the stream most recently created in this class.

◆ RandMrg() [2/2]

RandMrg ( String  name)

Constructs a new stream with an identifier name (can be used when printing the stream state, in error messages, etc.).

Parameters
namename of the stream

Member Function Documentation

◆ advanceState()

void advanceState ( int  e,
int  c 
)

Advances the state of this stream by \(k\) values, without modifying the states of other streams (as in setSeed), nor the values of \(B_g\) and \(I_g\) associated with this stream.

If \(e > 0\), then \(k=2^e + c\); if \(e < 0\), then \(k=-2^{-e} + c\); and if \(e = 0\), then \(k=c\). Note: \(c\) is allowed to take negative values. This method should be used only in very exceptional cases; proper use of the reset... methods and of the stream constructor cover most reasonable situations.

Parameters
ean exponent
ca constant

◆ clone()

RandMrg clone ( )

Clones the current generator and return its copy.

Returns
A deep copy of the current generator

Implements CloneableRandomStream.

◆ getState()

double [] getState ( )

Returns the current state \(C_g\) of this stream.

This is a vector of 6 integers represented in floating-point format. This method is convenient if we want to save the state for subsequent use.

Returns
the current state of the generator

◆ increasedPrecis()

void increasedPrecis ( boolean  incp)

After calling this method with incp = true, each call to the generator (direct or indirect) for this stream will return a uniform random number with (roughly) 53 bits of resolution instead of 32 bits, and will advance the state of the stream by 2 steps instead of.

  1. More precisely, if s is a stream of the class RandMrg, in the non-antithetic case, the instruction "<tt>u = s.nextDouble()</tt>", when the resolution has been increased, is equivalent to "<tt>u = (s.nextDouble() + s.nextDouble()*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 a number with 32 bits of resolution.

Parameters
incptrue if increased precision is desired, false otherwise

◆ nextArrayOfDouble()

void nextArrayOfDouble ( double []  u,
int  start,
int  n 
)

Generates n (pseudo)random numbers from the uniform distribution and stores them into the array u starting at index start.

Parameters
uarray that will contain the generated uniforms
startstarting index, in the array u, to write uniforms from
nnumber of uniforms to generate

Implements RandomStream.

◆ nextArrayOfInt()

void nextArrayOfInt ( int  i,
int  j,
int []  u,
int  start,
int  n 
)

Generates n (pseudo)random numbers from the discrete uniform distribution over the integers \(\{i,i+1,…,j\}\), using this stream and stores the result in the array u starting at index start.

(Calls nextInt n times.)

Parameters
ismallest integer that can be generated
jgreatest integer that can be generated
uarray that will contain the generated values
startstarting index, in the array u, to write integers from
nnumber of values being generated

Implements RandomStream.

◆ nextDouble()

double nextDouble ( )

Returns a (pseudo)random number from the uniform distribution over the interval \((0,1)\), using this stream, after advancing its state by one step.

Normally, the returned number has 32 bits of resolution, in the sense that it is always a multiple of \(1/(2^{32}-208)\). However, if the precision has been increased by calling increasedPrecis for this stream, the resolution is higher and the stream state advances by two steps.

Implements RandomStream.

◆ nextInt()

int nextInt ( int  i,
int  j 
)

Returns a (pseudo)random number from the discrete uniform distribution over the integers \(\{i,i+1,…,j\}\), using this stream.

(Calls nextDouble once.)

Parameters
ismallest integer that can be generated
jgreatest integer that can be generated
Returns
the generated integer

Implements RandomStream.

◆ setPackageSeed()

static void setPackageSeed ( long  seed[])
static

Sets the initial seed for the class RandMrg to the six integers in the vector seed[0..5].

This will be the seed (initial state) of the first stream. If this method is not called, the default initial seed is \((12345, 12345, 12345, 12345, 12345, 12345)\). If it is called, the first 3 values of the seed must all be less than \(m_1 = 4294967087\), and not all 0; and the last 3 values must all be less than \(m_2 = 4294944443\), and not all 0.

Parameters
seedarray of 6 elements representing the seed

◆ setSeed()

void setSeed ( long  seed[])

Sets the initial seed \(I_g\) of this stream to the vector seed[0..5].

This vector must satisfy the same conditions as in setPackageSeed. The stream is then reset to this initial seed. The states and seeds of the other streams are not modified. As a result, after calling this method, the initial seeds of the streams are no longer spaced \(Z\) values apart. For this reason, this method should be used only in very exceptional situations; proper use of reset... and of the stream constructor is preferable.

Parameters
seedarray of 6 integers representing the new seed

◆ toString()

String toString ( )

Returns a string containing the current state of this stream.

Returns
the state of the generator formated as a string

Implements RandomStream.

◆ toStringFull()

String toStringFull ( )

Returns a string containing the name of this stream and the values of all its internal variables.

Returns
the detailed state of the generator, formatted as a string

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