GetRNGstate and PutRNGstate

View: New views
2 Messages — Rating Filter:   Alert me  

GetRNGstate and PutRNGstate

by Tyler Smith :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

--

______________________________________________
R-devel@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Re: GetRNGstate and PutRNGstate

by Prof Brian Ripley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 3 Jul 2008, tyler wrote:

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


> 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
>
> --
>
> ______________________________________________
> R-devel@... mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Brian D. Ripley,                  ripley@...
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
LightInTheBox - Buy quality products at wholesale price!