Random-numbers are widely used for simulation, estimation andexploration. Many excellent pseudo-random number generators areavailable, and the literature keeps evolving.GeorgeMarsaglia had introduced a number of these, as well as the testbatterydiehard (laterextended byRobert Brownindieharder,see also thegithubrepo).
A particular generator,Ziggurat,was introduced in aJSSpaper in 2000 byMarsaglia andTsang. A small correction appeared in aJSS paper in 2005 byLeong et al. This version, along with improvements due toBurkhardt andVoss, is provided inour R packageRcppZiggurat,along with other implementations allowing for detailed comparison.
However, this existing R package provides a heavier build, andimposes run-time limits as it also links to the GNU GSL (for the methodbyVoss) as well asimplementation fromgretlandquantlib. The new packageassembled here offers a lighter-weight alternative. It can be calleddirectly from R, and also offers a C(++)-callable interface otherpackages can use in their native code as we demonstrate via fourdifferent sample client packages each connecting in a slightly differentway.
The following chart is generated by the example scriptexample/timings.R

It shows that the speed gains fromzigg relative to baseR are (for this example, on our machine) on the order of 7.4, 5.2, and4.7 for the normal, exponential, and uniform RRNGs.
That said, the actual time drawing random numbers will likely onlyaffect a fraction of the run-time of study so one may well considersticking with either the high-quality, well-tested, and widely-deployeddefault generators available in R, or in other CRAN package. Thispackage provides a useful illustration of how and older and simplergenerator can be lighter and faster (at possibly a lesser total periodetc).
The precedingdemo/timings.Rshows the basic usage from R. This works as usual:
library(zigg)# load packagezrnorm(5)# draw five N(0,1) distributed variateThe package can also be used in compiled code—even infourdifferent ways. All are demonstrated in included demo packages andperform similarly but offer different approaches.
src/init.c using a standard R mechanism for as exportedobject code that can be called directly (and consult theWritingR Extensions manual for details);The code is provided as an R package so a standard installation fromthe repository via
remotes::install_packages("zigg")work. The package has no dependencies.
Moreover, the package can be installed (as binary, where available,or source) from itsr-universerepository via
urls<-c("https://eddelbuettel.r-universe.dev","https://cloud.r-project.org")install.packages('zigg',repos = urls)and is also available as an Ubuntu binary, seethedocs for that).
Dirk Eddelbuettel
GPL (>= 2)
Initially created: Fri Jan 31 08:20:49 AM CST 2025
Last modified: Fri Jan 31 13:43:50 CST 2025