.DESLib.RandomLib.CMRG.UsersGuide

Information

Users Guide of the CMRG Package

CMRG package is the implementation in Modelica of the RNG algorithm proposed by L'Ecuyer et al. (pdf)
This RNG algorithm belongs to the Combined Multiple Recursive Generators family and combines two recursive generators of order 3.

The RNG implemented in CMRG package has a period close to 2^191.
This generator gives the possibility of creating multiple streams and sub-streams than can be considered as independent RNGs.
The whole period of the generator can be divided into disjoint streams, each of length 2^127. At the same time, each stream can be divided into 2^51 adjacent sub-streams, each of length 2^76.

The main class in the CMRG package is the RngStream. It represents a single stream of sequential random numbers.
As mentioned above, an RngStream is divided into adjacent sub-streams. The state of the RngStream indicates the start, current and next position in the current stream and sub-stream.

Package Structure

The CMRG package is composed of: 1) the developer package, called Src; and 2) the set of public functions.
The developer package contains the private part of the package. This package includes contants and functions to perform the required calculations to manage the state of the RngStreams. They have no utility for an standard user.
The public functions describe the operations that a user can perform with an RngStream, such as generating random numbers, updating the state of the stream or changing the package seed among others.
The operation of each function is described in its documentation.

Random Number Generation

In order to generate uniform random numbers using CMRG package the user has to:

Notice that the updated state of the RngStream has to be used to generate the next random number.

The following example represents the steps indicated above.

model usingCMRG
  // declaration of the streams
  CMRG.RngStream g1;
  Real u1[6];
algorithm
  when initial() then
    // stream initialization
    g1 := CMRG.RngStream_CreateStream();
  end when;
  when time <= 0 then
    for i in 1:6 loop
      // generation of random numbers from g1
      (u1[i],g1):= CMRG.RngStream_RandU01(g1);
    end for;
  end when;
end usingCMRG;

Several independent sources of random numbers can be created by declaring several RngStreams. The initialization of each declared RngStream will give it a different initial state.
The package seed is automatically managed, so it is not required to set an initial seed.


Generated at 2024-11-21T19:25:40Z by OpenModelicaOpenModelica 1.24.2 using GenerateDoc.mos