Seeds and Linear Congruence

In this blog, we will look at one mechanisms that are used in RiskyProject to randomize the values generated for Monte Carlo simulation. When you perform sampling, you need to generate random values for each statistical distribution. This happens every time during each iteration for all variables, for example for duration and cost of all tasks. This can cause a couple of issues:

  1. It may significantly affect calculation performance: though this is less of an issue with latest generation of computers.
  2. Every time you run a Monte Carlo simulation the results will differ because the analysis uses random inputs. This can be a major inconvenience because of the expectation that you will get the same results every time you perform the same analysis on the same schedule. If you run a large number of iterations, there will not be a significant difference between simulation results, but it still can confound your expectations.

The solution around the latter issue that we use in RiskyProject is called pseudorandom number generator. In this case, the software will only generate a random number only once when you first assign a statistical distribution to the task or resource parameter. This number is recorded and is used as a starting point of the calculation. This random number is called the seed. After the seed is generated, the next value for the second iteration of Monte Carlo process is generated as a function of the seed. The third value is generated as a function of the second value and so on. In other words, this sequence is predefined. In RiskyProject seed for all statistical distributions, such as distribution for task’s cost, income, duration, start time, is presented together with other distribution parameters:

How do computers generate random numbers? Generally, there are two types of random number generators. One type is based on some physical phenomena, such as radioactive decay or atmospheric noise. These physical effects can be programmed in the Monte Carlo software. The second type of random number generators are based on computational algorithms, which is employed in RiskyProject.  Monte Carlo simulation of project schedules does not require an extremely high quality random number generation algorithm. However, it should be of a reasonable quality to ensure that seeds are actually randomly generated.

RiskyProject uses a common pseudorandom number generator called linear congruential generator. The sequence of numbers is generated using very simple recursive equation:

X n+1 = A*X n + C

Where A is a multiplier, C is an increment, and X is the sequence of pseudorandom values. X0 is a seed. The value has a limit, for example 2,147,483,648, which is 231. When a pseudorandom number reaches this limit 231, it will be subtracted from result of the formula. For this formula to generate high quality pseudorandom numbers, A and C must be selected very carefully. Example of A is 1,103,515,245 or C is 12,345.