[Rcpp-devel] Rcpp bug with rgamma

Dirk Eddelbuettel edd at debian.org
Sun Oct 3 23:29:19 CEST 2010


Colin,

Just as one last comment, the issue at hand is described in Section 6.3 of
Writing R Extensions:

   6.3 Random number generation
   ============================
   
   The interface to R's internal random number generation routines is
   
        double unif_rand();
        double norm_rand();
        double exp_rand();
   
   giving one uniform, normal or exponential pseudo-random variate.
   However, before these are used, the user must call
   
        GetRNGstate();
   
   and after all the required variates have been generated, call
   
        PutRNGstate();
   
   These essentially read in (or create) `.Random.seed' and write it out
   after use.

   [...]

We had not made that sufficiently clear. What you encountered with rgamma was
an internal algorithm using a rejection sampleing scheme calling unif_rand()
and exp_rand() ... but creating an infinite loop at it would always end up
with the same draws.

I amended the 'Rcpp-sugar' vignette as well as the header files to point
users to this Section 6.3 to make sure GetRNGstate() and PutRNGstate() are
used.

Cheers,  Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list