# Random Number Generation

## Summary of topic

This page discusses random number generation, which could be useful to actuaries in monte-carlo simulation, stoctastic modelling etc.

## Those working on the topic

Declan Lavelle - declanlavelle@hld.ie

Nigel De Silva - nigel.desilva@thomasmiller.com

## Getting Started

For many actuarial applications involving monte-carlo simulation the Excel random number generator may not be suitable due to the relatively low period of the Excel random number generator, and problems of low order serial correlation in the numbers generated. For a brief discussion of these issues see Appendix E of this this paper by Carrett and Wong from the Australian Institute of Actuaries.

In their paper Carrett and Wong suggest the use of the Parks Miller Algorithm with Bayes Durham shuffle in preference to the Excel random number generator. This algorithm has been suggested as a “Minimal Standard” for pseudo-random number generators, and is described in detail in chapter 7 of “Numerical Recipes in C : The Art of Scientific Computing”.

### An Excel Implementation of Parks Miller Bayes Durham Algorithm

This spreadsheet contains a VBA implementation of the algorithm. ** You will need to download the workbook to get it to work, as it needs to write the random number file to your PC.** The macro allows the user to generate a csv file of random numbers. Each row corresponds to a “simulation” and each simulation can contain a user-defined number of random numbers. Leave the seed value blank to have a randomly chosen seed. Alternatively, to regenerate a file based on a known seed, key in the required seed value.

I would welcome any reviews, corrections, efficiency improvements of the VBA code. Feel free to use to use, modify or correct this spreadsheet as you wish. There are no guarantees as to its accuracy!

### Random Number Generation in R

R implements a number of random number generators. Full details can be found here. However, the default is the "Mersenne-Twister" algorithm which is "a twisted GFSR with period 2^19937 - 1 and equidistribution in 623 consecutive dimensions (over the whole period)." The implementation is incredibly fast, with a million random numbers generated in 0.26 seconds on my crappy laptop!

R also contains functions to create random numbers from a wide variety of distributions, such as the normal, multivariate normal, weibull, gamma, etc.

Here is some very simple code to output some uniform random numbers to a csv file.

The random package for R offers access to non deterministic (i.e. true) random numbers from www.random.org.

### PRNG

PRNGis a portable, high-performance ANSI-C implementation of pseudorandom number generators such as linear congruential, inversive congruential, and explicit inversive congruential random number generators (called LCG, ICG and EICG, respectively).

## Comments

Add your comments here

Some comments

## Comments (0)

You don't have permission to comment on this page.