SSJ
3.3.1
Stochastic Simulation in Java

This class provides a convenient foundation on which RNGs can be built. More...
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: \(C_g\) is set to \(B_g\).  
abstract 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\).  
abstract String  toString () 
Returns a string containing the current state of this stream. More...  
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). More...  
double  nextDouble () 
Returns a uniform random number between 0 and 1 from the stream. More...  
void  nextArrayOfDouble (double[] u, int start, int n) 
Calls nextDouble n times to fill the array u . More...  
int  nextInt (int i, int j) 
Calls nextDouble once to create one integer between i and j . More...  
void  nextArrayOfInt (int i, int j, int[] u, int start, int n) 
Calls nextInt n times to fill the array u . More...  
String  formatState () 
Use the toString method.  
String  formatStateFull () 
Use the toStringFull method.  
RandomStreamBase  clone () 
Clones the current generator and return its copy. More...  
Protected Member Functions  
abstract double  nextValue () 
This method should return the next random number (between 0 and 1) from the current stream. More...  
Protected Attributes  
String  name = null 
boolean  prec53 = false 
boolean  anti = false 
Static Protected Attributes  
static double  invtwo24 = 5.9604644775390625e8 
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 53bits 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
.
RandomStreamBase clone  (  ) 
Clones the current generator and return its copy.
Implements CloneableRandomStream.
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).
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
.
incp  if the generator will be set to high precision mode 
void nextArrayOfDouble  (  double []  u, 
int  start,  
int  n  
) 
Calls nextDouble
n
times to fill the array u
.
u  the array in which the numbers will be stored 
start  the first index of u to be used 
n  the number of random numbers to put in u 
Implements RandomStream.
void 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.
i  the smallest possible integer to put in u 
j  the largest possible integer to put in u 
u  the array in which the numbers will be stored 
start  the first index of u to be used 
n  the number of random numbers to put in u 
Implements RandomStream.
double 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.
Implements RandomStream.
int 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.
i  the smallest possible returned integer 
j  the largest possible returned integer 
Implements RandomStream.

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.

abstract 
Returns a string containing the current state of this stream.
Implements RandomStream.