[Rcpp-devel] RInside constructor calls srand

Dirk Eddelbuettel edd at debian.org
Mon Nov 7 20:22:57 CET 2011


On 7 November 2011 at 13:48, Joseph Xu wrote:
| Hi Dirk:
| 
| On Sun, Nov 6, 2011 at 10:22 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
| > I now see where you are coming from. Adding 'RInside' to an existing program
| > alters the (non-R-generated) random number stream of that program.  Is that
| > correct?
| >
| > In that case the sequence
| >
| >        RInside r(0, NULL);
| >        srand(1);
| >        r.parseEvalQ("set.seed(0)");
| >        cout << rand() << endl;
| >        return 0;
| >
| > may work as you now fix the RNG you care about (from the C library) after
| > setting up RInside.
| 
| Yes, this makes my program behave as I want. My main point is that the
| srand call in the RInside constructor is sneaky and users like me
| won't be aware of it. Maybe it would be better to force the user to
| initialize the random seed manually?

No --- RInside behaves just like R, including setting up its own randomized
temporary directory just like R does.

That is a feature, not a bug.

You probably shouldn't use rand() and srand() anyway.  Libc upgraded to
decent RNGs but the ones in R are likely to be of higher quality.

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