Random number generator and sampling algorithms used in Tamara

Random number generation is at the heart of Monte Carlo estimates. The algorithms used in Tamara for generating the random samples from probability distributions are the same as the ones used in ModelRisk, a risk analysis modelling software used by thousands of companies across the World.

Random number generator

A random number generator is an algorithm producing seemingly random numbers between 0 and 1 with equal probability and no observable pattern between generated values. Tamara uses the Mersenne Twister to generate random numbers for sampling from all probability distributions. It is the default random number generator in many of the most respected mathematical and statistical applications, including ModelRisk, R, Python, Maple, MATLAB, GAUSS, Stata, Microsoft Visual C++, and SPSS.

Sampling from a Bernoulli distribution

Let r be a random sample from the Mersenne Twister. Then the algorithm used to sample from a Bernoulli(p) distribution where  is as follows:

If r < p Then 1 Else 0

Sampling from a Poisson distribution

Let r be a random sample from the Mersenne Twister. Then the algorithm used to sample from a Poisson(l) distribution where 0 < l is as follows:

G(l;x+1,1) > r > G(l;x,1)

where G is the incomplete Gamma function ratio, which is calculated using an algorithm with 14-15 significant digit precision algorithm adapted from the Cephes library written by Stephen L. Moshier. The identity uses a known mathematical relationship between the Poisson and Gamma distributions with the advantage that it is stable for all values of l and x. Tamara then uses a numerical search algorithm to find the required value of x.

When l = 0 the Poisson sample is evaluated as 0. Negative values are not allowed.

Sampling from a Modified PERT distribution

Let r be a random sample from the Mersenne Twister. Tamara uses a shape factor of 3 for the Modified PERT distribution. Let a, b and c be the minimum, mode and maximum values for the Modified PERT distribution, and a < b < c. The distribution is a rescaled Beta distribution as follows:

ModPERT(a, b, c, 3) = a + (c - b) x Beta(a, b)

where:

The sampling algorithm for the Beta distribution is performed by numerically solving the equation:

The incomplete Beta function ratio  is calculated using a 14 significant digit precision algorithm described in Didonato and Morris (1992) [1].

Sampling from a ThreePointEstimate distribution

Let r be a random sample from the Mersenne Twister. The ThreePointEstimate distribution is a reparameterized Modified PERT distribution with shape parameter = 3. Tamara defines the high value to be the P90 of the distribution. Let a, b and h be the minimum, mode and high values for the ThreePointEstimate distribution, and a < b < h. The distribution is a rescaled Beta distribution as follows:

 ThreePointEstimate(a, b, h) = a + (c - b) x Beta(a, b)

where c is the unspecified maximum value of the distribution. Tamara first numerically solves for a, b and c  under the conditions:

 

c > h

 : to match the defined mode

: to match the defined 90th percentile

 : to match the shape assumed for the Modified PERT

 

The equations are then solved for a, b and c. The sampling algorithm for the Beta distribution is performed by numerically solving the equation:

The incomplete Beta function ratio  is calculated using a 14 significant digit algorithm described in Didonato and Morris (1992).

 



[1] Didonato A. and Morris A. (1992) “Significant digit computation of the incomplete beta function ratios”, ACM Transactions on Mathematical Software (TOMS) 18(3), 360-373

 

ModelRisk

Monte Carlo simulation in Excel. Learn more

Tamara

Adding risk and uncertainty to your project schedule. Learn more

Navigation

FREE MONTE CARLO SIMULATION SOFTWARE

For Microsoft Excel

Download your free copy of ModelRisk Basic today. Professional quality risk modeling software and no catches

Download ModelRisk Basic now

FREE PROJECT RISK SOFTWARE

For Primavera & Microsoft Project

Download your free copy of Tamara Basic today. Professional quality project risk software and no catches.

Download Tamara Basic now
-->