.DESLib.RandomLib.Variates.UsersGuide

Information

Users Guide of the Variates Library

Variates package contains a set of functions for generating random observations from the following probability distributions.

Discrete Probability Distributions: Continuous Probability Distributions:

Most of the algorithms used for generating the random variates are detailed in "Simulation Modeling and Analysis" (Averill M. Law, McGraw Hill, 2007), or the documentation of the Arena Simulation environment.

Library Structure

The structure of the Variates package is divided in three components: 1) general type and functions; 2) Discrete package; and 3) Continuous package.

The general type and functions mainly contain the Generator record, which represent the source for uniform random numbers that will be used by the U01 function, which is the function that generates uniform random numbers.
Each Generator must be initialized using the function initGenerator.
Var function is a prototype for the rest of variate generation functions.
GenerateVariate is a function that accepts an integer parameter that indicates the probability distribution for the random variate.
The Constant function generates a constant number, indicated as a parameter.

Package Discrete contains the functions for generating random variates following discrete probability distributions.

Package Continuous, analogously to the previous, contains the functions for generating random variates following continuous probability distributions.

Each function of these packages contains a description of the random variates that generates.

Random Variate Generation

In order to generate uniform random observations using Variates package the user has to:

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

The following example represents the steps indicated above.

 model usingVariates
  // declaration of the generator
  Variates.Generator g1;
  Real u1[6];
algorithm
  when initial() then
    // generator initialization
    g1 := Variates.initGenerator();
  end when;
  when time <= 0 then
    for i in 1:6 loop
      // generation of random variates from g1 with Exponential(8) distribution.
      (u1[i],g1):= Variates.Continuous.Exponential(g1,8);
    end for;
  end when;
end usingVariates;

//results: u1 = {1.20419,12.282,0.713961,5.28482,7.26866,41.0291}

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

Use Another Source of Uniform Random Numbers

CMRG is the default uniform random number generator for the Variates package. However, Variates package can be used with any other Modelica library for uniform random generation.
To use other uniform random number generator with the Variates package the following requirements have to me meet:


Once the new random number generator meets these requirements, the Variates Generator, initGenerator and U01 values has to be set to the ones in the new random number generator.
Generated at 2024-11-21T19:25:40Z by OpenModelicaOpenModelica 1.24.2 using GenerateDoc.mos