ziggurat: Collection of Ziggurat Normal RNGs

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

This package regroups and provides a nummber of implementations of the Ziggurat generator for drawing (standard) normally distributed random numbers. Ziggurat was introduced by Marsaglia and Tsang (JSS, 2000) and improved by Leong, Zhang, et al (JSS, 2005).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21

Arguments

n

An integer determining the length of the returned N(0,1) vector.

x

A numeric vector, already allocated, that is to filled with N(0,1) draws.

s

An integer number used to seed the Ziggurat algorithm.

p

An numeric vector of length four with the state parameters.

Details

The ‘MT’ variants provide the original Marsaglia and Tsang implementation, updated to work in 32 and 64 bit environments. Their use is not recommended.

The ‘LZLLV’ variants provide the updated Marsaglia and Tsang implementation, based on the comment by Leong, Zhang, Luk, Lee and Villasenor. These versions should be suitable. The code has also been updated to work in 32 and 64 bit environments.

The ‘V1’ variants are based on an earlier implementation by John Burkardt. While fastest, they also correspond to just the Marsaglia and Zhang approach and should not be used.

The function zrnorm() (and corresponding seed setter zsetseed() and getter zgetseed()) is the recommended implementation based on merging John Burkardt earlier code with the Leong et al improvements.

The zrnormGSL functions use the GNU GSL implementation by Jochen Voss. They too can be recommended for use.

The functions zrnormQL and zrnormGl use, respectively, functions adapted from the GNU Gretl and QuantLib projects. They have been added primarily for comparison to the other engines.

The function zrnormR uses the unif_rand uniform generator from R (which defaults to the Mersenne Twister). It is useful when the Zigurrat generator is used as a user-supplied generator in R. However, it stores state in R's internal structures which makes it a little slower than other alternatives available here.

Value

The zrnorm* functions all return a vector of the requested size.

The zsetseed* functions do not return a value, but set the seed of the generator.

The zgetseed* functions return the (integer) seed. This is actually not sufficient to capture the state, so zgetpars zsetpars provide this functionality with a vector of size four. Use these functions with caution.

Author(s)

Dirk Eddelbuettel

References

George Marsaglia and Wai Wan Tsang. The Ziggurat Method for Generating Random Variables. Journal of Statistical Software, Vol 5, Iss 8, Oct 2000 https://www.jstatsoft.org/v05/i08

Philip H W Leong, Ganglie Zhang, Dong-U Lee, Wayne Luk, and John Villasenor. A Comment on the Implementation of the Ziggurat method, Journal of Statistical Software, Vol 12, Iss 7, Feb 2005 https://www.jstatsoft.org/v12/i07

Website of John Burkardt. https://people.sc.fsu.edu/~jburkardt/

Website of Jochen Voss. https://www.seehuhn.de/pages/ziggurat

See Also

RcppZiggurat-package

Examples

1
2
3
4
5
  set.seed(42)
  system.time(replicate(500, rnorm(10000)))

  zsetseed(42)
  system.time(replicate(500, zrnorm(10000)))

Example output

   user  system elapsed 
  0.807   0.063   0.873 
   user  system elapsed 
  0.249   0.082   0.338 

RcppZiggurat documentation built on Oct. 23, 2020, 8:09 p.m.