[Rcpp-devel] R random numbers vs c++

Dirk Eddelbuettel edd at debian.org
Thu Mar 22 13:51:27 CET 2012


On 22 March 2012 at 13:41, Glenn Lawyer wrote:
| Is there a reason to prefer Rcpp::runif over the c++ rand() for, say, accepting
| a state in a Markov chain simulation? Is one more random than another? faster?

Fair question.  I'd say go with R because

 - it is portable as R supplies it, and well tested by R Core (specifically
   Brian Ripley who actually "did write the book on this")

 - six different generators you can select from

 - numerous distributions

whereas system library rand() implementations used to be terrible.  But you
could also consider Boost or others.

As for speed, we were benchmarking some MCMC stuff against Python in response
to a post by Darren Wilkinson last year. Turned out that R's rgamma was
slower that one from the GSL, which I discussed briefly with Martin Maechler.
It "may" be that R's rgamma is more rigorous / better.

Dirk

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list