SEED Instruction |
SEED value
The SEED instruction allows you to supply a seed value for the random number generator. This is generally used to help you test programs that involve random draws, by forcing the same random sequence each time you run the program.
Parameters
|
value |
The desired seed. If value is 0 or omitted, RATS computes a new seed using the current date and time. You can select any other value as your seed. While it is common to choose “random-looking” numbers like the 13939 below, they have no particular advantage over seeds like 1 or 777. |
Description
The seed is an integer which initializes the RATS random number generator. This generator is used by the instructions SIMULATE and BOOT and by the functions such as %RAN, %UNIFORM, %RANGAMMA and %RANWISHART. The seed uniquely determines the sequence of (pseudo-) random numbers. The algorithms used are provided below.
RATS normally sets the seed using the time and date at which the program begins execution. This default seed will be different each time you run the program.
Instead, you can use SEED to rerun a program with the same set of generated numbers. This is very helpful when you are testing a program which draws random numbers, as it is easier to find and fix coding errors when your “data” doesn’t change each time you run the program.
Put SEED right at the beginning of your code so it will be easy to remove once the program is running correctly.
Notes
SEED only permits you to reproduce random numbers when you use exactly the same instructions in the same sequence. Consider, for instance,
declare vector b1(5) b2(5) b(10)
seed 13939
compute b=%ran(1.0)
seed 13939
compute b1=%ran(1.0)
compute b2=%ran(1.0)
The entries of B1 match the first five entries of B. However, the entries of B2 are different from the last five entries of B. Technically, RATS uses an acceptance-rejection algorithm for generating Normal values from uniform. This requires an extra draw from the uniform at the beginning of each set of numbers.
Algorithms
RATS uses the period \(2^{191}\) pseudo-random number generator from L’Ecuyer (1999). This generates the same set of numbers from a given seed on any platform supported by RATS. Real numbers in the range [0,1] are obtained from this by dividing the integer by its period. These are used directly by the function %UNIFORM (possibly with scaling and translation to fit the desired range) and BOOT.
Normal and gamma deviates are generated from the uniforms by acceptance-rejection algorithms.
Copyright © 2026 Thomas A. Doan