Hi Dirk, Thanks very much for your thoughtful reply. This is a relief for me as my 'solution' for replacing the existing RNG in my C++ was convoluted and I couldn't see the advantage in doing so. Thank you for the search tip -- that is really helpful and I did not know that there was this kind of mirroring. Thanks also for the mention of the rcpp-devel -- I think I will use that instead next time.
One point of contention though -- I think the Writing R-Extensions page could be more explicit in this regard and perhaps suggest times/examples when it is OK to include an existing (3rd party) RNG and when it is not. I also think that it would be helpful if R offered a way to instantiate multiple instances of its internal RNG manager out of the box -- the RNG state management strategy appears almost 'magical' to me especially inside RCPP. It is possible, I just don't understand how to use it. Best, -John On Fri, Sep 27, 2024 at 4:19 PM Dirk Eddelbuettel <e...@debian.org> wrote: > > 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 | e...@debian.org > [[alternative HTML version deleted]] ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel