ziggurat: Collection of Ziggurat Normal RNGs

zrnormR Documentation

Collection of Ziggurat Normal RNGs

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

  zrnorm(n)
  zrnormLZLLV(n)
  zrnormMT(n)
  zrnormV1(n)
  zrnormVec(x)
  zrnormVecV1(x)
  zrnormGSL(n)
  zrnormQL(n)
  zrnormGl(n)
  zrnormR(n)
  zsetseed(s)
  zsetseedV1(s)
  zsetseedLZLLV(s)
  zsetseedGSL(s)
  zsetseedQL(s)
  zsetseedGl(s)
  zsetseedMT(s)
  zgetseed()
  zgetseedV1()
  zgetpars()
  zsetpars(p)

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 doi: 10.18637/jss.v005.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 doi: 10.18637/jss.v012.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

  set.seed(42)
  system.time(replicate(500, rnorm(10000)))

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

eddelbuettel/rcppziggurat documentation built on Dec. 4, 2022, 2:30 a.m.