Skip to content
Back to formatted view

Raw Message

Message-ID: <CAGvvAh1hGzoz5GLyaDBV29-YDADwbr3Crb8ZR1BQPk1Smg_13w@mail.gmail.com>
Date: 2011-11-07T18:48:19Z
From: Joseph Xu
Subject: [Rcpp-devel] RInside constructor calls srand
In-Reply-To: <20150.42564.508336.681052@max.nulle.part>

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?

Joseph