g05yn initializes a scrambled quasi-random generator prior to calling

**g05ym**(G05YJF not in this release) (G05YKF not in this release). It must be preceded by a call to one of the pseudorandom initialization methods (G05KFF not in this release) (G05KGF not in this release).# Syntax

C# |
---|

public static void g05yn( int genid, int stype, int idim, int[] iref, int iskip, int nsdigi, G05..::..G05State g05state, out int ifail ) |

Visual Basic |
---|

Public Shared Sub g05yn ( _ genid As Integer, _ stype As Integer, _ idim As Integer, _ iref As Integer(), _ iskip As Integer, _ nsdigi As Integer, _ g05state As G05..::..G05State, _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void g05yn( int genid, int stype, int idim, array<int>^ iref, int iskip, int nsdigi, G05..::..G05State^ g05state, [OutAttribute] int% ifail ) |

F# |
---|

static member g05yn : genid : int * stype : int * idim : int * iref : int[] * iskip : int * nsdigi : int * g05state : G05..::..G05State * ifail : int byref -> unit |

#### Parameters

- genid
- Type: System..::..Int32
*On entry*: must identify the quasi-random 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$.

- stype
- Type: System..::..Int32
*On entry*: must identify the scrambling method to use.- ${\mathbf{stype}}=0$
- No scrambling. This is equivalent to calling g05yl.
- ${\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$.

- idim
- Type: System..::..Int32
*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$.

- iref
- Type: array<System..::..Int32>[]()[][]An array of size [liref]
*On exit*: contains initialization information for use by the generator methods (G05YJF not in this release) (G05YKF not in this release)**g05ym**. iref must not be altered in any way between initialization and calls of the generator methods.

- iskip
- Type: System..::..Int32
*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}$.

- nsdigi
- Type: System..::..Int32
*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.

- g05state
- Type: NagLibrary..::..G05..::..G05StateAn Object of type G05.G05State.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

g05yn selects a quasi-random 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 methods

**g05ym**(G05YJF not in this release) (G05YKF not in this release).Scrambled quasi-random sequences are an extension of standard quasi-random sequences that attempt to eliminate the bias inherent in a quasi-random sequence whilst retaining the low-discrepancy 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 quasi-random 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$.

# References

Bratley P and Fox B L (1988) Algorithm 659: implementing Sobol's quasirandom sequence generator

*ACM Trans. Math. Software***14(1)**88–100Faure H and Tezuka S (2000) Another random scrambling of digital (t,s)-sequences

*Monte Carlo and Quasi-Monte Carlo Methods*Springer-Verlag, 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–109Jäckel P (2002)

*Monte Carlo Methods in Finance*Wiley Finance Series, John Wiley and Sons, EnglandJoe S and Kuo F Y (2003) Remark on Algorithm 659: implementing Sobol's quasirandom sequence generator

*ACM Trans. Math. Software (TOMS)***29**49–57Joe S and Kuo F Y (2008) Constructing Sobol sequences with better two-dimensional projections

*SIAM J. Sci. Comput.***30**2635–2654Niederreiter H (1988) Low-discrepancy and low dispersion sequences

*Journal of Number Theory***30**51–70Owen A B (1995) Randomly permuted (t,m,s)-nets and (t,s)-sequences

*Monte Carlo and Quasi-Monte Carlo Methods in Scientific Computing, Lecture Notes in Statistics***106**Springer-Verlag, New York, NY 299–317 (eds H Niederreiter and P J-S Shiue)# Error Indicators and Warnings

Errors or warnings detected by the method:

- ${\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.

# Accuracy

Not applicable.

# Parallelism and Performance

None.

# Further Comments

The additional computational cost in using a scrambled quasi-random sequence over a non-scrambled one comes entirely during the initialization. Once g05yn has been called the computational cost of generating a scrambled sequence and a non-scrambled one is identical.