umontreal.iro.lecuyer.rng
Class MRG31k3p
- java.lang.Object
-
- umontreal.iro.lecuyer.rng.RandomStreamBase
-
- umontreal.iro.lecuyer.rng.MRG31k3p
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, CloneableRandomStream, RandomStream
public class MRG31k3p extends RandomStreamBase
Extends the abstract classRandomStreamBase, thus implementing theRandomStreaminterface indirectly. The backbone generator is the combined multiple recursive generator (CMRG) MRG31k3p proposed by L'Ecuyer and Touzin, implemented in 32-bit integer arithmetic. This RNG has a period length of approximately 2185. The values of V, W and Z are 262, 272 and 2134 respectively. (SeeRandomStreamfor their definition.) The seed and the state of a stream at any given step are six-dimensional vectors of 32-bit integers. The default initial seed is (12345, 12345, 12345, 12345, 12345, 12345). The method nextValue provides 31 bits of precision.The difference between the RNG of class
MRG32k3aand this one is that this one has all its coefficients of the form a = ±2q±2r. This permits a faster implementation than for arbitrary coefficients. On a 32-bit computer, MRG31k3p is about twice as fast as MRG32k3a. On the other hand, the latter does a little better in the spectral test and has been more extensively tested.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description MRG31k3p()Constructs a new stream, initialized at its beginning.MRG31k3p(java.lang.String name)Constructs a new stream with the identifier name (used when formatting the stream state).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description MRG31k3pclone()Clones the current generator and return its copy.int[]getState()Returns the current state Cg of this stream.voidresetNextSubstream()Reinitializes the stream to the beginning of its next substream: Ng is computed, and Cg and Bg are set to Ng.voidresetStartStream()Reinitializes the stream to its initial state Ig: Cg and Bg are set to Ig.voidresetStartSubstream()Reinitializes the stream to the beginning of its current substream: Cg is set to Bg.static voidsetPackageSeed(int[] seed)Sets the initial seed for the class MRG31k3p to the six integers of the vector seed[0..5].voidsetSeed(int[] seed)Use of this method is strongly discouraged.java.lang.StringtoString()Returns a string containing the current state of this stream.-
Methods inherited from class umontreal.iro.lecuyer.rng.RandomStreamBase
formatState, formatStateFull, increasedPrecision, nextArrayOfDouble, nextArrayOfInt, nextDouble, nextInt
-
-
-
-
Constructor Detail
-
MRG31k3p
public MRG31k3p()
Constructs a new stream, initialized at its beginning. Its seed is Z = 2134 steps away from the previous seed.
-
MRG31k3p
public MRG31k3p(java.lang.String name)
Constructs a new stream with the identifier name (used when formatting the stream state).- Parameters:
name- name of the stream
-
-
Method Detail
-
setPackageSeed
public static void setPackageSeed(int[] seed)
Sets the initial seed for the class MRG31k3p to the six integers of the vector seed[0..5]. This will be the initial state (or seed) of the next created stream. By default, if this method is not called, the first stream is created with the seed (12345, 12345, 12345, 12345, 12345, 12345). If it is called, the first 3 values of the seed must all be less than m1 = 2147483647, and not all 0; and the last 3 values must all be less than m2 = 2147462579, and not all 0.- Parameters:
seed- array of 6 elements representing the seed
-
setSeed
public void setSeed(int[] seed)
Use of this method is strongly discouraged. Initializes the stream at the beginning of a stream with the initial seed seed[0..5]. This vector must satisfy the same conditions as in setPackageSeed. This method only affects the specified stream, all the others are not modified, so the beginning 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:
seed- array of 6 integers representing the new seed
-
resetStartStream
public void resetStartStream()
Description copied from interface:RandomStreamReinitializes the stream to its initial state Ig: Cg and Bg are set to Ig.- Specified by:
resetStartStreamin interfaceRandomStream- Specified by:
resetStartStreamin classRandomStreamBase
-
resetStartSubstream
public void resetStartSubstream()
Description copied from interface:RandomStreamReinitializes the stream to the beginning of its current substream: Cg is set to Bg.- Specified by:
resetStartSubstreamin interfaceRandomStream- Specified by:
resetStartSubstreamin classRandomStreamBase
-
resetNextSubstream
public void resetNextSubstream()
Description copied from interface:RandomStreamReinitializes the stream to the beginning of its next substream: Ng is computed, and Cg and Bg are set to Ng.- Specified by:
resetNextSubstreamin interfaceRandomStream- Specified by:
resetNextSubstreamin classRandomStreamBase
-
getState
public int[] getState()
Returns the current state Cg of this stream. This is a vector of 6 integers represented. This method is convenient if we want to save the state for subsequent use.- Returns:
- the current state of the generator
-
clone
public MRG31k3p clone()
Clones the current generator and return its copy.- Specified by:
clonein interfaceCloneableRandomStream- Overrides:
clonein classRandomStreamBase- Returns:
- A deep copy of the current generator
-
toString
public java.lang.String toString()
Description copied from interface:RandomStreamReturns a string containing the current state of this stream.- Specified by:
toStringin interfaceRandomStream- Specified by:
toStringin classRandomStreamBase- Returns:
- the state of the generator formated as a string
-
-
DMelt 3.0 © DataMelt by jWork.ORG