Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_rand_init_nonrepeat (g05kg)

## Purpose

nag_rand_init_nonrepeat (g05kg) initializes the selected base generator to generate a non-repeatable sequence of variates. The base generator can then be used by the group of pseudorandom number functions (see nag_rand_init_leapfrog (g05kh)nag_rand_init_skipahead (g05kj), nag_rand_permute (g05nc), nag_rand_sample (g05nd), nag_rand_times_garch_asym1 (g05pd)nag_rand_times_mv_varma (g05pj), nag_rand_matrix_orthog (g05px)nag_rand_matrix_2waytable (g05pz), nag_rand_copula_students_t (g05rc), nag_rand_copula_normal (g05rd), nag_rand_multivar_students_t (g05ry), nag_rand_multivar_normal (g05rz) and nag_rand_dist_uniform01 (g05sa)nag_rand_int_uniform (g05tl)) and the quasi-random scrambled sequence initialization function, nag_rand_quasi_init_scrambled (g05yn).

## Syntax

[state, ifail] = g05kg(genid, subid)
[state, ifail] = nag_rand_init_nonrepeat(genid, subid)

## Description

nag_rand_init_nonrepeat (g05kg) selects a base generator through the input value of the arguments genid and subid, and then initializes it based on the values taken from the real-time clock, resulting in the same base generator yielding different sequences of random numbers each time the calling program is run. It should be noted that there is no guarantee of statistical properties between sequences, only within sequences.
A definition of some of the terms used in this description, along with details of the various base generators can be found in the G05 Chapter Introduction.

## References

L'Ecuyer P and Simard R (2002) TestU01: a software library in ANSI C for empirical testing of random number generators Departement d'Informatique et de Recherche Operationnelle, Universite de Montreal http://www.iro.umontreal.ca/~lecuyer
Maclaren N M (1989) The generation of multiple independent sequences of pseudorandom numbers Appl. Statist. 38 351–359
Matsumoto M and Nishimura T (1998) Mersenne twister: a 623-dimensionally equidistributed uniform pseudorandom number generator ACM Transactions on Modelling and Computer Simulations
Wichmann B A and Hill I D (2006) Generating good pseudo-random numbers Computational Statistics and Data Analysis 51 1614–1622
Wikramaratna R S (1989) ACORN - a new method for generating sequences of uniformly distributed pseudo-random numbers Journal of Computational Physics 83 16–31

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{genid}$int64int32nag_int scalar
Must contain the type of base generator to use.
${\mathbf{genid}}=1$
NAG basic generator.
${\mathbf{genid}}=2$
Wichmann Hill I generator.
${\mathbf{genid}}=3$
Mersenne Twister.
${\mathbf{genid}}=4$
Wichmann Hill II generator.
${\mathbf{genid}}=5$
ACORN generator.
${\mathbf{genid}}=6$
L'Ecuyer MRG32k3a generator.
See the G05 Chapter Introduction for details of each of the base generators.
Constraint: ${\mathbf{genid}}=1$, $2$, $3$, $4$, $5$ or $6$.
2:     $\mathrm{subid}$int64int32nag_int scalar
If ${\mathbf{genid}}=2$, subid indicates which of the $273$ sub-generators to use. In this case, the  sub-generator is used.
If ${\mathbf{genid}}=5$, subid indicates the values of $k$ and $p$ to use, where $k$ is the order of the generator, and $p$ controls the size of the modulus, $M$, with $M={2}^{\left(p×30\right)}$. If ${\mathbf{subid}}<1$, the default values of $k=10$ and $p=2$ are used, otherwise values for $k$ and $p$ are calculated from the formula, ${\mathbf{subid}}=k+1000\left(p-1\right)$.
If ${\mathbf{genid}}=6$ and  the range of the generator is set to $\left(0,1\right]$, otherwise the range is set to $\left(0,1\right)$; in this case the sequence is identical to the implementation of MRG32k3a in TestU01 (see L'Ecuyer and Simard (2002)) for identical seeds.
For all other values of genid, subid is not referenced.

None.

### Output Parameters

1:     $\mathrm{state}\left(\mathit{lstate}\right)$int64int32nag_int array
Contains information on the selected base generator and its current state.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{genid}}=1$, $2$, $3$, $4$, $5$ or $6$.
${\mathbf{ifail}}=4$
Constraint: $\mathit{lstate}\le 0$ or .
${\mathbf{ifail}}=-1$
Required length of state array returned in lstate but state array not initialized.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Not applicable.

None.

## Example

This example prints the first five pseudorandom real numbers from a uniform distribution between $0$ and $1$, generated by nag_rand_dist_uniform01 (g05sa) after initialization by nag_rand_init_nonrepeat (g05kg).
```function g05kg_example

fprintf('g05kg example results\n\n');

% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);

% Initialize the generator to an unrepeatable sequence
[state, ifail] = g05kg(genid, subid);

% The number of pseudorandom numbers to be generated
n = int64(5);

% Generate the variates
[state, x, ifail] = g05sa( ...
n, state);

% Display variates
disp(x);

```
```g05kg example results

0.3331
0.5686
0.7844
0.5503
0.1498

```