g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_quasi_rand_uniform (g05ymc)

## 1  Purpose

nag_quasi_rand_uniform (g05ymc) generates a uniformly distributed low-discrepancy sequence as proposed by Sobol, Faure or Niederreiter. 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_uniform (Nag_OrderType order, Integer n, double quas[], Integer pdquas, Integer iref[], 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_rand_uniform (g05ymc) generates a set of points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ with high uniformity in the $S$-dimensional unit cube ${I}^{S}={\left[0,1\right]}^{S}$.
Let $G$ be a subset of ${I}^{S}$ and define the counting function ${S}_{N}\left(G\right)$ as the number of points ${x}^{i}\in G$. For each $x=\left({x}_{1},{x}_{2},\dots ,{x}_{S}\right)\in {I}^{S}$, let ${G}_{x}$ be the rectangular $S$-dimensional region
 $G x = 0, x 1 × 0, x 2 ×⋯× 0, x S$
with volume ${x}_{1},{x}_{2},\dots ,{x}_{S}$. Then one measure of the uniformity of the points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ is the discrepancy:
 $DN* x1,x2,…,xN = sup x∈IS SN Gx - N x1 , x2 , … , xS .$
which has the form
 $DN*x1,x2,…,xN≤CSlog⁡NS+Olog⁡NS-1 for all N≥2.$
The principal aim in the construction of low-discrepancy sequences is to find sequences of points in ${I}^{S}$ with a bound of this form where the constant ${C}_{S}$ is as small as possible.
The type of low-discrepancy sequence generated by nag_quasi_rand_uniform (g05ymc) depends on the initialization function called and can include those proposed by Sobol, Faure or Niederreiter. If the initialization function nag_quasi_init_scrambled (g05ync) was used then the sequence will be scrambled (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

## 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 function 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 Nag_ColMajor.
2:     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$.
3:     quas[${\mathbf{pdquas}}×\mathit{tdquas}$]doubleOutput
Note: 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: ${\mathbf{QUAS}}\left(i,j\right)$ holds the $i$th value for the $j$th dimension.
4:     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_RowMajor}$, ${\mathbf{pdquas}}\ge \mathit{idim}$;
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdquas}}\ge {\mathbf{n}}$.
5:     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.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

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}}〉$, $\mathit{idim}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdquas}}\ge \mathit{idim}$.
On entry, ${\mathbf{pdquas}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\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_TOO_MANY_CALLS
On entry, value of n would result in too many calls to the generator: ${\mathbf{n}}=〈\mathit{\text{value}}〉$, generator has previously been called $〈\mathit{\text{value}}〉$ times.

Not applicable.

None.

## 9  Example

This example calls nag_quasi_init (g05ylc) and nag_quasi_rand_uniform (g05ymc) to estimate the value of the integral
 $∫01 ⋯ ∫01 ∏ i=1 s 4xi-2 dx1, dx2, …, dxs = 1 .$
In this example the number of dimensions $S$ is set to $8$.

### 9.1  Program Text

Program Text (g05ymce.c)

None.

### 9.3  Program Results

Program Results (g05ymce.r)