g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_quasi_rand_normal (g05yjc)

## 1  Purpose

nag_quasi_rand_normal (g05yjc) generates a quasi-random sequence from a Normal (Gaussian) distribution. It must be preceded by a call to one of the initialization functions nag_quasi_init (g05ylc) or nag_quasi_init_scrambled (g05ync).

## 2  Specification

 #include #include
 void nag_quasi_rand_normal (Nag_OrderType order, const double xmean[], const double std[], Integer n, double quas[], Integer pdquas, Integer iref[], NagError *fail)

## 3  Description

nag_quasi_rand_normal (g05yjc) generates a quasi-random sequence from a Normal distribution by first generating a uniform quasi-random sequence which is then transformed into a Normal sequence using the inverse of the Normal CDF. The type of uniform sequence used depends on the initialization function called and can include the low-discrepancy sequences proposed by Sobol, Faure or Niederreiter. If the initialization function nag_quasi_init_scrambled (g05ync) was used then the underlying uniform sequence is first scrambled prior to being transformed (see Section 3 in nag_quasi_init_scrambled (g05ync) for details).

## 4  References

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
Wichura (1988) Algorithm AS 241: the percentage points of the Normal distribution Appl. Statist. 37 477–484

## 5  Arguments

Note: the following variables are used in the parameter descriptions:
• $\mathit{idim}={\mathbf{idim}}$, the number of dimensions required, see nag_quasi_init (g05ylc) or nag_quasi_init_scrambled (g05ync);
• $\mathit{liref}={\mathbf{liref}}$, the length of iref as supplied to the initialization functions nag_quasi_init (g05ylc) or nag_quasi_init_scrambled (g05ync).
• $\mathit{tdquas}={\mathbf{n}}$ if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$; otherwise $\mathit{tdquas}=\mathit{idim}$
1:     orderNag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:     xmean[$\mathit{idim}$]const doubleInput
On entry: specifies, for each dimension, the mean of the Normal distribution.
3:     std[$\mathit{idim}$]const doubleInput
On entry: specifies, for each dimension, the standard deviation of the Normal distribution.
Constraint: ${\mathbf{std}}\left[\mathit{i}-1\right]\ge 0.0$, for $\mathit{i}=1,2,\dots ,\mathit{idim}$.
4:     nIntegerInput
On entry: the number of quasi-random numbers required.
Constraint: ${\mathbf{n}}\ge 0$ and ${\mathbf{n}}+\text{previous number of generated values}\le {2}^{31}-1$.
5:     quas[$\mathit{dim}$]doubleOutput
Note: the dimension, dim, of the array quas must be at least ${\mathbf{pdquas}}×\mathit{idim}$.
The dimension, dim, of the array quas must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdquas}}×\mathit{idim}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdquas}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
Where ${\mathbf{QUAS}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{quas}}\left[\left(j-1\right)×{\mathbf{pdquas}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{quas}}\left[\left(i-1\right)×{\mathbf{pdquas}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On exit: contains the n quasi-random numbers of dimension idim, ${\mathbf{QUAS}}\left(i,j\right)$ holds the $i$th value for the $j$th dimension.
6:     pdquasIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array quas.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdquas}}\ge {\mathbf{n}}$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdquas}}\ge \mathit{idim}$.
7:     iref[$\mathit{liref}$]IntegerCommunication Array
On entry: contains information on the current state of the sequence.
On exit: contains updated information on the state of the sequence.
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_INITIALIZATION
On entry, iref has either not been initialized or has been corrupted.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
NE_INT_2
On entry, ${\mathbf{pdquas}}=⟨\mathit{\text{value}}⟩$ and $\mathit{idim}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdquas}}\ge \mathit{idim}$.
On entry, ${\mathbf{pdquas}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdquas}}\ge {\mathbf{n}}$.
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_REAL_ARRAY
On entry, ${\mathbf{std}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{std}}\left[i\right]\ge 0.0$.
NE_TOO_MANY_CALLS
There have been too many calls to the generator.

Not applicable.

## 8  Parallelism and Performance

nag_quasi_rand_normal (g05yjc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_quasi_rand_normal (g05yjc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
The Sobol, Sobol (A659) and Niederreiter quasi-random number generators in nag_quasi_rand_normal (g05yjc) have been parallelized, but require quite large problem sizes to see any significant performance gain. Parallelism is only enabled when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$. The Faure generator is serial.

None.

## 10  Example

This example calls nag_quasi_init (g05ylc) to initialize the generator and then nag_quasi_rand_normal (g05yjc) to generate a sequence of five four-dimensional variates.

### 10.1  Program Text

Program Text (g05yjce.c)

None.

### 10.3  Program Results

Program Results (g05yjce.r)