NAG Library Routine Document
G05YNF
1 Purpose
G05YNF initializes a scrambled quasirandom generator prior to calling
G05YJF,
G05YKF or
G05YMF. It must be preceded by a call to one of the pseudorandom initialization routines
G05KFF or
G05KGF.
2 Specification
INTEGER 
GENID, STYPE, IDIM, IREF(LIREF), LIREF, ISKIP, NSDIGI, STATE(*), IFAIL 

3 Description
G05YNF selects a quasirandom number generator through the input value of
GENID, a method of scrambling through the input value of
STYPE and initializes the
IREF communication array for use in the routines
G05YJF,
G05YKF or
G05YMF.
Scrambled quasirandom sequences are an extension of standard quasirandom sequences that attempt to eliminate the bias inherent in a quasirandom sequence whilst retaining the lowdiscrepancy properties. The use of a scrambled sequence allows error estimation of Monte–Carlo results by performing a number of iterates and computing the variance of the results.
This implementation of scrambled quasirandom sequences is based on TOMS Algorithm 823 and details can be found in the accompanying paper,
Hong and Hickernell (2003). Three methods of scrambling are supplied; the first a restricted form of Owen's scrambling (
Owen (1995)), the second based on the method of
Faure and Tezuka (2000) and the last method combines the first two.
Scrambled versions of the Niederreiter sequence and two sets of Sobol sequences are provided. The first Sobol sequence is obtained using
${\mathbf{GENID}}=1$. The first 10000 direction numbers for this sequence are based on the work of
Joe and Kuo (2008). For dimensions greater than 10000 the direction numbers are randomly generated using the pseudorandom generator specified in
STATE (see
Jäckel (2002) for details). The second Sobol sequence is obtained using
${\mathbf{GENID}}=2$ and referred to in the documentation as ‘Sobol (A659)’. The first 1111 direction numbers for this sequence are based on Algorithm 659 of
Bratley and Fox (1988) with the extension proposed by
Joe and Kuo (2003). For dimensions greater than 1111 the direction numbers are once again randomly generated. The Niederreiter sequence is obtained by setting
${\mathbf{GENID}}=3$.
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
Faure H and Tezuka S (2000) Another random scrambling of digital (t,s)sequences Monte Carlo and QuasiMonte Carlo Methods SpringerVerlag, Berlin, Germany (eds K T Fang, F J Hickernell and H Niederreiter)
Hong H S and Hickernell F J (2003) Algorithm 823: implementing scrambled digital sequences ACM Trans. Math. Software 29:2 95–109
Jäckel P (2002) Monte Carlo Methods in Finance Wiley Finance Series, John Wiley and Sons, England
Joe S and Kuo F Y (2003) Remark on Algorithm 659: implementing Sobol's quasirandom sequence generator ACM Trans. Math. Software (TOMS) 29 49–57
Joe S and Kuo F Y (2008) Constructing Sobol sequences with better twodimensional projections SIAM J. Sci. Comput. 30 2635–2654
Niederreiter H (1988) Lowdiscrepancy and low dispersion sequences Journal of Number Theory 30 51–70
Owen A B (1995) Randomly permuted (t,m,s)nets and (t,s)sequences Monte Carlo and QuasiMonte Carlo Methods in Scientific Computing, Lecture Notes in Statistics 106 SpringerVerlag, New York, NY 299–317 (eds H Niederreiter and P JS Shiue)
5 Parameters
 1: GENID – INTEGERInput
On entry: must identify the quasirandom generator to use.
 ${\mathbf{GENID}}=1$
 Sobol generator.
 ${\mathbf{GENID}}=2$
 Sobol (A659) generator.
 ${\mathbf{GENID}}=3$
 Niederreiter generator.
Constraint:
${\mathbf{GENID}}=1$, $2$ or $3$.
 2: STYPE – INTEGERInput
On entry: must identify the scrambling method to use.
 ${\mathbf{STYPE}}=0$
 No scrambling. This is equivalent to calling G05YLF.
 ${\mathbf{STYPE}}=1$
 Owen like scrambling.
 ${\mathbf{STYPE}}=2$
 Faure–Tezuka scrambling.
 ${\mathbf{STYPE}}=3$
 Owen and Faure–Tezuka scrambling.
Constraint:
${\mathbf{STYPE}}=0$, $1$, $2$ or $3$.
 3: IDIM – INTEGERInput
On entry: the number of dimensions required.
Constraints:
 if ${\mathbf{GENID}}=1$, $1\le {\mathbf{IDIM}}\le 50000$;
 if ${\mathbf{GENID}}=2$, $1\le {\mathbf{IDIM}}\le 50000$;
 if ${\mathbf{GENID}}=3$, $1\le {\mathbf{IDIM}}\le 318$.
 4: IREF(LIREF) – INTEGER arrayCommunication Array
On exit: contains initialization information for use by the generator routines
G05YJF,
G05YKF and
G05YMF.
IREF must not be altered in any way between initialization and calls of the generator routines.
 5: LIREF – INTEGERInput
On entry: the dimension of the array
IREF as declared in the (sub)program from which G05YNF is called.
Constraint:
${\mathbf{LIREF}}\ge 32\times {\mathbf{IDIM}}+7$.
 6: ISKIP – INTEGERInput
On entry: the number of terms of the sequence to skip on initialization for the Sobol and Niederreiter generators.
Constraint:
$0\le {\mathbf{ISKIP}}\le {2}^{30}$.
 7: NSDIGI – INTEGERInput
On entry: controls the number of digits (bits) to scramble when
${\mathbf{GENID}}=1$ or
$2$, otherwise
NSDIGI is ignored. If
${\mathbf{NSDIGI}}<1$ or
${\mathbf{NSDIGI}}>30$ then all the digits are scrambled.
 8: STATE($*$) – INTEGER arrayCommunication Array

Note: the actual argument supplied must be the array
STATE supplied to the initialization routines
G05KFF or
G05KGF.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
 9: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
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 parameter, 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.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
 ${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{GENID}}\ne 1$, $2$ or $3$.
 ${\mathbf{IFAIL}}=2$
${\mathbf{STYPE}}\ne 0$, $1$, $2$ or $3$.
 ${\mathbf{IFAIL}}=3$
On entry,  ${\mathbf{IDIM}}<1$, 
or  IDIM is too large. 
 ${\mathbf{IFAIL}}=5$
On entry,
LIREF is too small.
 ${\mathbf{IFAIL}}=6$
The value of
${\mathbf{ISKIP}}<0$ or
ISKIP is too large.
 ${\mathbf{IFAIL}}=8$
On entry,  STATE vector was not initialized or has been corrupted. 
7 Accuracy
Not applicable.
The additional computational cost in using a scrambled quasirandom sequence over a nonscrambled one comes entirely during the initialization. Once G05YNF has been called the computational cost of generating a scrambled sequence and a nonscrambled one is identical.
9 Example
This example calls
G05KFF,
G05YMF and G05YNF to estimate the value of the integral
where
$s$, the number of dimensions, is set to
$8$.
9.1 Program Text
Program Text (g05ynfe.f90)
9.2 Program Data
Program Data (g05ynfe.d)
9.3 Program Results
Program Results (g05ynfe.r)