Using Random Numbers

The primitives Random* found in the Number Generators library replaces the wide range of primitives that were previously available and have been moved to Compatibility→NumberGenerators. Every time the primitive is executed it generates a value that is a random deviate drawn from the distribution selected by parameter Distribution.

The following distributions are available (along with their parameters):

Binominal
Trials, Probability, Seed
Exponential
Mean, Seed
Normal
Mean, Variance, Seed
Poisson
Mean, Seed
Uniform
Min, Max, Seed

A separate seed value can be defined for each instance of the primitive which determines whether a local seed is used, a generated seed is used or the global seed is used.

The usage of the seed value is as follows:

Positive
The given seed value is used as local seed, that is, all instances with the same seed generate the same sequence of deviates on each simulation run.
Negative
The global seed is used. All instances generate different sequences during a simulation run, but each instance generates the same sequence of deviates on consecutive simulation runs.
Zero
A unique seed value is computed using current system time. All instances generate different sequences during the simulation run and each instance generates a different sequence of deviates on consecutive simulation runs.

The following code must be used (duplicated code indicates that it can be used in either the setup or the go method):

hinclude { <Rng/Normal.h> }
protected
{
  Rng::Normal mRandom;
}
setup
{
  mRandom.setMean(MeanValue);
  mRandom.setVariance(VarianceValue);
  mRandom.setSeed(SeedValue);
}
go
{
  mRandom.setMean(MeanValue);
  mRandom.setVariance(VarianceValue);
  mRandom.setSeed(SeedValue);
  Output%0 << mRandom();
}