RandomSeed
System Variable RandomSeed
The random samples and random numbers generated by Analytica, or by any other software, are not truly random. They are called pseudo-random sequences. They are generated by deterministic algorithms. When these algorithms are started from the same initial state, they will reproduce the same random sequence. The "random seed" captures the state of the pseudo-random number algorithm.
This system variable allows you to reset the RandomSeed to an integer value.
The value of the system variable does not change as random numbers are generated, even though the internal seed does change. The internal seed has many more bits than fit in a single number, and is not accessible. Instead, RandomSeed stays at the previous value that you set it to. If the model is saved after you change this, then the random number generator will start from that new seed after your model is loaded.
You are allowed to assign to RandomSeed using the Assignment Operator := even from variable Definitions, which of course is in direct violation to the "no side-effects rule". (But, you should not change it using EvaluateScript while a variable is evaluating). Previously generated random numbers are NOT invalidated from this assignment. Doing this is quite useful when you want to ensure that your sequence always comes out the same, independent of the order in which the user evaluates variables, and independent of the number of times the variable has been re-evaluated.
Example
The Definition of a Chance variable might be:
RandomSeed := 9;
Normal(0,1)
If you have a second chance variable that is also Normal(0,1) distributed, you would use a different RandomSeed number so that its sample is not identical to the first variable.
Notes
= Assignment vs. EvaluateScript
Changing RandomSeed using an assignment operator is not the same as setting it from typescript. When set from an expression using the assignment operator, previously evaluated random numbers are not invalidated. But when set from typescript or by using EvaluateScript, all previously cached uncertain variables are invalidated.
RandomSeed := 5; Uniform(0,1)
{ Generates a repeatable sequence }EvaluateScript("RandomSeed:5")
{ Invalidates all uncertain variables in the model }
You should never set it via EvaluateScript while a variable evaluation is in-progress. In general, EvaluateScript should always be avoided from expressions when a variable evaluation is in-progress, since it does let you do things that are not legitimate. It is, however, sometimes used as a hack, for example, to enact a side-effect that you know is safe despite the no-side-effect rule (which would generally mean that the side-effect does not impact any upstream variables of the current variable, and is not upstream from any computed indexes that might appear in tables, choices, etc.). RandomSeed is almost guaranteed to me upstream, and hence is almost always dangerous to set via EvaluateScript.
See Also
- Distribution Functions
- Random() function
- SampleType
- RandomType
Enable comment auto-refresher