[Rcpp-devel] RInside constructor calls srand

Joseph Xu josephzxu at gmail.com
Mon Nov 7 19:48:19 CET 2011

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?


More information about the Rcpp-devel mailing list