RcppZiggurat: Rcpp integration of different Ziggurat Normal RNGs


Random numbers are of critical importance for simulations. In particular, those following a standard normal distribution are frequently used.

R, as a system and environment for statistical programming, comes with several generators for the normal distribution. However, while these are thoroughly tested and well-regarded for their statistical properties, these builtin-generators are not among the fastest generators.

The following figure, taken from the detailed pdf vignette, illustrates the speed to four different Ziggurat implementations relative to the default R generator. It displays violin plots of the results aggregated by the microbenchmark package, running 100 replications of one million draws each:

Speed comparison between Ziggurat RNGs and default R generator

We can also illustrate it with the standard benchmark table:

R> library(rbenchmark)
R> n <- 1e6
R> benchmark(rnorm(n), zrnorm(n))[,1:4]
       test replications elapsed relative
1  rnorm(N)          100  11.643     9.27
2 zrnorm(N)          100   1.256     1.00

For settings in which the RNG draws constitutes a measurable amount of time, the gain can be noticeable. In other situations, the about nine-fold gain may be somewhat immaterial as it affects only a small part of the overall execution.


Please see the detailed pdf vignette (also included in the package) for more details on the algorithm, the statistical validation and the timing comparisons.


The Ziggurat algorithm was introducded by Marsaglia and Tsang (2000) in a well-known JSS paper. An important correction was published by Leong et al (2005), also in JSS.

Several Open Source implementations exists. We compare the following three in our vignette: the version in the GNU GSL due to Jochen Voss, a version from GNU Gretl, and an experimental version from QuantLib.

Where do I get it

The package is available


RcppZiggurat is written and maintained by Dirk Eddelbuettel.


RcppZiggurat is licensed under the GNU GPL version 2 or later.

Last modified: Mon Dec 23 18:50:36 CST 2013