# genr8

genr8 returns a vector of pseudorandom number sequence.

## Syntax

• out=genr8(n)example
• out=genr8(n, distrib)example
• out=genr8(n, distrib, s1)example
• out=genr8(n, distrib, s1, s2)example

## Description

This function generates a sequence of pseudorandom numbers using the 32-bit rnadom number generator from figure 3 of the article by Pierre L'Ecuyer.

The cycle length is claimed to be 2.30584E+18.

 out =genr8(n) genr8 using all default arguments.

 out =genr8(n, distrib) genr8 specifing the type of distribution.

 out =genr8(n, distrib, s1) genr8 specifing the type of distribution and 1 seed.

 out =genr8(n, distrib, s1, s2) genr8 specifing the type of distribution and the 2 seeds.

## Examples

expand all

### genr8 using all default arguments.

out = genr8(1)

### genr8 specifing the type of distribution.

% a vector of 5 uniform distributed random numbers
out = genr8(5, 0)
% a vector of 10 normal distributed random numbers
out = genr8(10, 1)

### genr8 specifing the type of distribution and 1 seed.

% vector of 5 uniform distributed random numbers and 1 seed
out = genr8(5, 0, 12345)
% vector of 50 normal distributed random numbers and 1 seed
out = genr8(10, 1, 45678)

### genr8 specifing the type of distribution and the 2 seeds.

% vector of 5 uniform distributed random numbers with both seeds
out = genr8(5, 0, 12345, 45678)
% vector of 50 normal distributed random numbers with both seeds
out = genr8(10, 1, 12345, 45678)

## Input Arguments

### n — Number of random numbers. Positive integer.

The number of random numbers to generate.

Data Types: integer value

### distrib — Distribution. Scalar 0 or 1.

Default is distrib=0 that indicates the use of the uniform distribution in [0 1], while distrib=1 indicates the use of the standard normal with 0 mean and standard deviation 1 Data Types - integer value

Data Types:

### s1 — First value used as the seed for the sequence. Scalar.

Whenever needed, the user can initialize s1 to a value between 1 and 2147483562.

Example: 4356123 

Data Types: integer value

### s2 — Second value used as the seed for the sequence. Scalar.

Whenever needed, s2 can be initialized to a value between 1 and 2147483398.

Example: 123 

Data Types: integer value

## Output Arguments

### out —Generated random sequence. random sequence. Vector. n x 1 vector

The Mersenne Twister algorithm is the most used RNG among statistical software, but most implementations contain slightly variations that make difficult to obtain random numbers sequences that are congruent across platforms. This simple yet powerful algorithm is a variation of the well known Wichmann Hill RNG but boasts an impressive cycle length of 2.30584E+18. Given the sheer but clear structure and the lack of specific mathematical operators, the coding should be easily reproducible across all platforms.

## References

L'Ecuyer, P. (1988), Efficient and Portable Combined Random Number Generators, "Communications of the ACM", Vol. 31, pp. 742-751.

Wichmann, B. and Hill, D. (1982), An Efficient and Portable Pseudo-random Number Generator, "Applied Statistics", Vol. 31, pp. 188-190.

## Acknowledgements

Original PASCAL version by Pierre L'Ecuyer.

Modifications by John Burkardt.

Further modifications by FSDA team