nag_quasi_random_normal (g05ybc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_quasi_random_normal (g05ybc)

## 1  Purpose

To generate multidimensional quasi-random sequences with a Gaussian or log-normal probability distribution.

## 2  Specification

 #include #include
 void nag_quasi_random_normal (Nag_QuasiRandom_State state, Nag_QuasiRandom_Sequence seq, Nag_Distributions lnorm, const double mean[], const double std[], Integer iskip, Integer idim, double quasi[], Nag_QuasiRandom *gf, NagError *fail)

## 3  Description

Low discrepancy (quasi-random) sequences are used in numerical integration, simulation and optimization. Like pseudorandom numbers they are uniformly distributed but they are not statistically independent, rather they are designed to give more even distribution in multidimensional space (uniformity). Therefore they are often more efficient than pseudorandom numbers in multidimensional Monte–Carlo methods.
nag_quasi_random_normal (g05ybc) generates multidimensional quasi-random sequences with a Gaussian or log-normal probability distribution. The sequences are generated in pairs using the Box–Muller method. This means that an even number of dimensions are required by this function. If an odd number of dimensions are required then the extra dimension must be computed, but can then be ignored.
This function uses the sequences as described in nag_quasi_random_uniform (g05yac).

## 4  References

Box G E P and Muller M E (1958) A note on the generation of random normal deviates Ann. Math. Statist. 29 610–611
Bratley P and Fox B L (1988) Algorithm 659: implementing Sobol's quasirandom sequence generator ACM Trans. Math. Software 14(1) 88–100
Fox B L (1986) Algorithm 647: implementation and relative efficiency of quasirandom sequence generators ACM Trans. Math. Software 12(4) 362–376

## 5  Arguments

1:     stateNag_QuasiRandom_StateInput
On entry: the type of operation to perform.
${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$
The first call for initialization and there is no output via array quasi.
${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Cont}$
The sequence has already been initialized by a prior call to nag_quasi_random_normal (g05ybc) with ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$. Random numbers are output via array quasi.
${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Finish}$
The final call to release memory and no further random numbers are required for output via array quasi.
Constraint: ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$, $\mathrm{Nag_QuasiRandom_Cont}$ or $\mathrm{Nag_QuasiRandom_Finish}$.
2:     seqNag_QuasiRandom_SequenceInput
On entry: the type of sequence to generate.
${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Sobol}$
A Sobol sequence.
${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Nied}$
A Niederreiter sequence.
${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Faure}$
A Faure sequence.
Constraint: ${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Sobol}$, $\mathrm{Nag_QuasiRandom_Nied}$ or $\mathrm{Nag_QuasiRandom_Faure}$.
3:     lnormNag_DistributionsInput
On entry: indicates whether to create Gaussian or log-normal variates.
${\mathbf{lnorm}}=\mathrm{Nag_LogNormal}$
The variates are log-normal.
${\mathbf{lnorm}}=\mathrm{Nag_Normal}$
The variates are Gaussian.
Constraint: ${\mathbf{lnorm}}=\mathrm{Nag_LogNormal}$ or $\mathrm{Nag_Normal}$.
4:     mean[idim]const doubleInput
On entry: ${\mathbf{mean}}\left[k-1\right]$ is the mean of distribution for the $k$th dimension.
5:     std[idim]const doubleInput
On entry: ${\mathbf{std}}\left[k-1\right]$ is the standard deviation of the distribution for the $k$th dimension.
Constraint: ${\mathbf{std}}\left[\mathit{i}-1\right]>0.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{idim}}$.
6:     iskipIntegerInput
On entry: the number of terms in the sequence to skip on initialization.
If ${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Faure}$, iskip is not referenced.
Constraint: if ${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Nied}$ or $\mathrm{Nag_QuasiRandom_Sobol}$ and ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$, ${\mathbf{iskip}}\ge 0$.
7:     idimIntegerInput
On entry: the number of dimensions required.
Constraint: $2\le {\mathbf{idim}}\le 40$ and .
8:     quasi[idim]doubleOutput
On exit: the random numbers, generated in pairs. That is, on the first call with ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Cont}$, ${\mathbf{quasi}}\left[k-1\right]$ contains the first quasi-random number for the $k$th dimension. On the next call ${\mathbf{quasi}}\left[k-1\right]$ contains the second quasi-random number for the $k$th dimension, etc..
9:     gfNag_QuasiRandom *Communication Structure
Workspace used to communicate information between calls to nag_quasi_random_normal (g05ybc). The contents of this structure should not be changed between calls.
10:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_BAD_PARAM
On entry, seq is not valid: ${\mathbf{seq}}="〈\mathit{\text{value}}〉"$.
NE_INITIALIZATION
Incorrect initialization.
NE_INT
On entry, ${\mathbf{idim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{idim}}\le 40$.
On entry, ${\mathbf{idim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{idim}}\ge 2$.
On entry, idim is not even: ${\mathbf{idim}}=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{iskip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{iskip}}\ge 0$.
On entry, value of skip too large: ${\mathbf{iskip}}=〈\mathit{\text{value}}〉$.
NE_INT_ARRAY_ELEM_CONS
On entry, element $〈\mathit{\text{value}}〉$ of ${\mathbf{std}}\le 0.0$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_TOO_MANY_CALLS
Too many calls to generator.

Not applicable.

## 8  Further Comments

The maximum length of the generated sequences is ${2}^{29}-1$, this should be adequate for practical purposes. For more information see nag_quasi_random_uniform (g05yac).

## 9  Example

This example program calculates the sum of the expected values of the kurtosis of $20$ independent Gaussian samples. A quasi-random Faure sequence generator is used.

### 9.1  Program Text

Program Text (g05ybce.c)

None.

### 9.3  Program Results

Program Results (g05ybce.r)

nag_quasi_random_normal (g05ybc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual