Title: | Lightweight Interfaces to the 'Ziggurat' Pseudo Random Number Generator |
---|---|
Description: | The 'Ziggurat' pseudo-random number generator (or PRNG), introduced by Marsaglia and Tsang (2000, <doi:10.18637/jss.v005.i08>) and further improved by Leong et al (2005, <doi:10.18637/jss.v012.i07>), offers a lightweight and very fast PRNG for the normal, exponential, and uniform distributions. It is provided here in a small zero-dependency package. It can be used from R as well as from 'C/C++' code in other packages as is demonstrated by four included sample packages using four distinct methods to use the PRNG presented here in client package. The implementation is influenced by our package 'RcppZiggurat' which offers a comparison among multiple alternative implementations but presented here in a lighter-weight implementation that is easier to use by other packages. The PRNGs provided are generally faster than the ones in base R: on our machine, the relative gains for normal, exponential and uniform are on the order of 7.4, 5.2 and 4.7 times faster than base R. However, these generators are of potentially lesser quality and shorter period so if in doubt use of the base R functions remains the general recommendation. |
Authors: | Dirk Eddelbuettel [aut, cre]
|
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.2 |
Built: | 2025-03-09 07:02:21 UTC |
Source: | CRAN |
The 'Ziggurat' pseudo-random number generator (or PRNG), introduced by Marsaglia and Tsang (2000, <doi:10.18637/jss.v005.i08>) and further improved by Leong et al (2005, <doi:10.18637/jss.v012.i07>), offers a lightweight and very fast PRNG for the normal, exponential, and uniform distributions. It is provided here in a small zero-dependency package. It can be used from R as well as from 'C/C++' code in other packages as is demonstrated by four included sample packages using four distinct methods to use the PRNG presented here in client package. The implementation is influenced by our package 'RcppZiggurat' which offers a comparison among multiple alternative implementations but presented here in a lighter-weight implementation that is easier to use by other packages. The PRNGs provided are generally faster than the ones in base R: on our machine, the relative gains for normal, exponential and uniform are on the order of 7.4, 5.2 and 4.7 times faster than base R. However, these generators are of potentially lesser quality and shorter period so if in doubt use of the base R functions remains the general recommendation.
Index of help topics:
zigg-package Lightweight Interfaces to the 'Ziggurat' Pseudo Random Number Generator zrnorm Ziggurat Pseudo Random Number Generators
Dirk Eddelbuettel <[email protected]>
Dirk Eddelbuettel [aut, cre] (<https://orcid.org/0000-0001-6419-907X>)
Pseudo random numbers drawn from one of three distributions are offered, as proposed by Marsaglia and Tsang (2000, <doi:10.18637/jss.v005.i08>) and improved by Leong et al (2005, <doi:10.18637/jss.v012.i07>.
zrnorm(n) zrexp(n) zrunif(n) zsetseed(s)
zrnorm(n) zrexp(n) zrunif(n) zsetseed(s)
n |
The size of the returned vector |
s |
The chosen seed |
A vector of pseudo random-number generated draws from either the Normal, Exponential or Uniform distribution, as selected.
<doi:10.18637/jss.v005.i08> <doi:10.18637/jss.v012.i07>
zsetseed(123) zrnorm(3) round(summary(zrunif(1e6)), 4)
zsetseed(123) zrnorm(3) round(summary(zrunif(1e6)), 4)