Overview | Package | Class | Tree | Deprecated | Index | Help
| SSJ V. 2.1.1.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## umontreal.iro.lecuyer.rng
Class RandMrg

    java.lang.Object
      umontreal.iro.lecuyer.rng.RandMrg

All Implemented Interfaces:
  Serializable, Cloneable, CloneableRandomStream, RandomStream

    public class RandMrg

extends Object
implements CloneableRandomStream, Serializable

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

See Also:
  Serialized Form

Constructor Summary
`RandMrg()` Constructs a new stream, initializes its seed Ig, sets Bg and Cg equal to Ig, and sets its antithetic switch to `false`.
`RandMrg(String name)` Constructs a new stream with an identifier `name` (can be used when printing the stream state, in error messages, etc.).

Method Summary
`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 Bg and Ig associated with this stream.
`RandMrg` | `clone()` Clones the current generator and return its copy.
`double[]` | `getState()` Returns the current state Cg of this stream.
`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.
`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`.
`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`.
`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.
`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.
`void` | `resetNextSubstream()` Reinitializes the stream to the beginning of its next substream: Ng is computed, and Cg and Bg are set to Ng.
`void` | `resetStartStream()` Reinitializes the stream to its initial state Ig: Cg and Bg are set to Ig.
`void` | `resetStartSubstream()` Reinitializes the stream to the beginning of its current substream: Cg is set to Bg.
`void` | `setAntithetic(boolean anti)`
`static void` | `setPackageSeed(long[] seed)` Sets the initial seed for the class `RandMrg` to the six integers in the vector `seed[0..5]`.
`void` | `setSeed(long[] seed)` Sets the initial seed Ig of this stream to the vector `seed[0..5]`.
`String` | `toString()` Returns a string containing the current state of this stream.
`String` | `toStringFull()` Returns a string containing the name of this stream and the values of all its internal variables.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### RandMrg

    public RandMrg()

  Constructs a new stream, initializes its seed Ig, sets Bg and Cg equal to Ig, and sets its antithetic switch to `false`. The seed Ig is equal to the initial seed of the package given by `setPackageSeed` 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

    public RandMrg(String name)

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

  Parameters:
    `name` - name of the stream

Method Detail

### setPackageSeed

    public static void setPackageSeed(long[] seed)

  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 m1 = 4294967087, and not all 0; and the last 3 values must all be less than m2 = 4294944443, and not all 0.

  Parameters:
    `seed` - array of 6 elements representing the seed

### resetStartStream

    public void resetStartStream()

  Description copied from interface: `RandomStream`
  Reinitializes the stream to its initial state Ig: Cg and Bg are set to Ig.

  Specified by:
    `resetStartStream` in interface `RandomStream`

### resetStartSubstream

    public void resetStartSubstream()

  Description copied from interface: `RandomStream`
  Reinitializes the stream to the beginning of its current substream: Cg is set to Bg.

  Specified by:
    `resetStartSubstream` in interface `RandomStream`

### resetNextSubstream

    public void resetNextSubstream()

  Description copied from interface: `RandomStream`
  Reinitializes the stream to the beginning of its next substream: Ng is computed, and Cg and Bg are set to Ng.

  Specified by:
    `resetNextSubstream` in interface `RandomStream`

### increasedPrecis

    public 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 ```u = s.nextDouble()`'', when the resolution has been increased, is equivalent to ```u = (s.nextDouble() + s.nextDouble()*fact) % 1.0`'' 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:
    `incp` - `true` if increased precision is desired, `false` otherwise

### setAntithetic

    public void setAntithetic(boolean anti)

### advanceState

    public 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 Bg and Ig associated with this stream. If e > 0, then k = 2e + 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:
    `e` - an exponent
    `c` - a constant

### setSeed

    public void setSeed(long[] seed)

  Sets the initial seed Ig 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:
    `seed` - array of 6 integers representing the new seed

### getState

    public double[] getState()

  Returns the current state Cg 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

### toString

    public String toString()

  Description copied from interface: `RandomStream`
  Returns a string containing the current state of this stream.

  Specified by:
    `toString` in interface `RandomStream`
  Overrides:
    `toString` in class `Object`
  Returns:
    the state of the generator formated as a string

### toStringFull

    public 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

### nextDouble

    public 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/(232 - 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.

  Specified by:
    `nextDouble` in interface `RandomStream`
  Returns:
    the next generated uniform

### nextArrayOfDouble

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

  Description copied from interface: `RandomStream`
  Generates `n` (pseudo)random numbers from the uniform distribution and stores them into the array `u` starting at index `start`.

  Specified by:
    `nextArrayOfDouble` in interface `RandomStream`
  Parameters:
    `u` - array that will contain the generated uniforms
    `start` - starting index, in the array `u`, to write uniforms from
    `n` - number of uniforms to generate

### nextInt

    public int nextInt(int i,
                       int j)

  Description copied from interface: `RandomStream`
  Returns a (pseudo)random number from the discrete uniform distribution over the integers {i, i + 1,..., j}, using this stream. (Calls `nextDouble` once.)

  Specified by:
    `nextInt` in interface `RandomStream`
  Parameters:
    `i` - smallest integer that can be generated
    `j` - greatest integer that can be generated
  Returns:
    the generated integer

### nextArrayOfInt

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

  Description copied from interface: `RandomStream`
  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.)

  Specified by:
    `nextArrayOfInt` in interface `RandomStream`
  Parameters:
    `i` - smallest integer that can be generated
    `j` - greatest integer that can be generated
    `u` - array that will contain the generated values
    `start` - starting index, in the array `u`, to write integers from
    `n` - number of values being generated

### clone

    public RandMrg clone()

  Clones the current generator and return its copy.

  Specified by:
    `clone` in interface `CloneableRandomStream`
  Overrides:
    `clone` in class `Object`
  Returns:
    A deep copy of the current generator

Overview | Package | Class | Tree | Deprecated | Index | Help
| SSJ V. 2.1.1.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.