[R-pkg-devel] R-extension requirement about third-party random number generators (RNG)

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Fri Sep 27 16:19:24 CEST 2024


Hi John,

I think you are reading the text too literally. The intent of WRE is to
ensure that standard use of a RNG in an extension package uses the RNGs that
come with R (which includes an updated mersenne twister algorithm) so that
users are not "surprised".  It explicitly mentions the problem of multiple
seeding.  An example of how this can be done is in RcppArmadillo: a long time
ago we worked out a scheme were in the R use case the RNG is 'dropped in' so
that Armadillo code uses randu(5) you get what runif(5) in R would give you
(given the same seed from R).

On the other hand, when you know what you do and properly (locally)
instantiate another PRNG for local use you can. For quick checks I often use
a query at github in the 'cran' organisation mirroring the CRAN repos. For
example the following shows where std::mt19937 is used in C++ to deploy the
Mersenne Twister. So as you can see, when done carefully it is in fact
allowed.

   https://github.com/search?q=org%3Acran%20mt19937&type=code

Hope this helps, and allow me to mention that there is also the rcpp-devel
for more Rcpp-specific questions.

Cheers, Dirk


-- 
dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org



More information about the R-package-devel mailing list