[Rcpp-devel] RInside constructor calls srand

Joseph Xu josephzxu at gmail.com
Sun Nov 6 03:26:15 CET 2011


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.


Thanks for your time.

Joseph


More information about the Rcpp-devel mailing list