[Rcpp-devel] RInside constructor calls srand

Joseph Xu josephzxu at gmail.com
Sun Nov 6 07:18:57 CET 2011


Hi Dirk:

Thanks for the quick reply.

On Sat, Nov 5, 2011 at 11:06 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

> 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.

I tried something like this:

#include <stdlib.h>
#include <iostream>
#include <Rcpp.h>
#include <RInside.h>

using namespace std;

int main() {
	srand(1);
	RInside r(0, NULL);
	r.parseEvalQ("set.seed(0)");
	cout << rand() << endl;
	return 0;
}

But every time I run the program, I get a different random number. Am
I missing something?

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


Joseph


More information about the Rcpp-devel mailing list