Skip to content

GetRNGstate and PutRNGstate

2 messages · Tyler Smith, Brian Ripley

#
Hi,

I've got a simulation function, written in C and called from R, that
uses the R random number functions. It's not a very complicated
simulation - 280 lines total, with the main function (the one called
with .C) repeatedly calling another function, with multiple calls to
unif_rand() in both functions. At the beginning of the main function I
call GetRNGstate(), and the last thing I do before returning to R is
PutRNGstate().

On rereading Chapter 5 of the R Extensions manual, I'm not sure I
understand the GetRNGstate/PutRNGstate calls. Should I also include them
in the helper function? Do I need to wrap every call to unif_rand with
these calls, or is it ok that I've just used them at the beginning and
end of the C code? 

I'm getting different results from different simulations, so what I've
done appears ok, but I'm not sure I would be able to detect if every
call to the helper function was returning the same result.

Thanks,

Tyler

--
#
On Thu, 3 Jul 2008, tyler wrote:

            
I find the manual very much clearer than your email:

   However, before these are used, the user must call

      GetRNGstate();

   and after all the required variates have been generated, call

      PutRNGstate();

So in so far as I understand your prose, you followed that advice by 
calling *one of* them 'at the beginning and end of the C code'.