[Rcpp-devel] RInside constructor calls srand

Dirk Eddelbuettel edd at debian.org
Sun Nov 6 04:06:39 CET 2011


On 5 November 2011 at 22:26, Joseph Xu wrote:

Hi Joseph,

Thanks for posting here with questions about Rcpp and RInside.

| Hi:
| 
| I'm working on a program that uses RInside and also calls the rand()
| function. For the longest time I was trying to figure out why my
| program was behaving differently with every run even though I
| initialized the random seed to 1. Finally I found the problem was that
| the RInside constructor secretly calls srand with the current time.
| 
| I noticed a comment explaining that the srand call was needed by
| tempfile(), but is this absolutely necessary? How will tempfile()
| break if srand was static? It seems like a huge disadvantage to not be
| able to deterministically debug a program. At the very least, the call
| to srand should be made very obvious to the user.

Maybe you are missing the discussion about using R's RNG functions from the
'Writing R Extensions' manual, and how to init the state of the RNG?

Also, RInside embeds R. And just as in normal R, if you want reproducibility
from the embedded R provided by RInside, you need set.seed(). Just use it.

| Thanks for your time.

Pleasure. Hope this answers your question.

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