[R] generating normal numbers: GetRNGstate, PutRNGstate
Yongchao Ge
Yongchao.Ge at mssm.edu
Wed Mar 3 22:09:00 CET 2004
See my reply at the end of the email.
> > I'd like to generate thousands of normal numbers from my C function using
> > the C API functions provided R. I have two options:
> >
> > 1. double norm_rand(); (page 61 of R extension 1.8.1)
> > 2. double rnorm(double mu, double sigma); (page 58 of R extension 1.8.1)
>
> Page numbers depend on the paper size you used (and I guess you didn't use
> the world standard A4) but what I guess is your page 61 says
>
> See Random numbers, for the protocol in using the random-variate
> routines.
>
> and that refers you back to page 58.
>
> > If my understanding of R-exts is correct, then I only need to call
> > GetRNGstate once, and then call 1000 norm_rand, and then call
> > PutRNGstate once for the 1st option.
> >
> > For the 2nd option, I have to call 1000 times for each of GetRNGstate,
> > rnorm, and PutRNGstate.
>
> That is *not* what the manual says. Just the same as 1).
>
Hi Prof Ripley
Thank you for the answers. Sorry for the misconfusion of the pages numbers
as the "local standard" here is using "letter" size, not "A4".
The following is the last paragraph above section 6.4
The C code behind R's rxxx functions can be accessed by including the
header file Rmath.h ; See Section 5.7.1 [Distribution functions], page
61. Those calls generate a single variate and should also be enclosed in
calls to GetRNGstate and PutRNGstate.
Note the "*** generate a single variate and should also be enclosed in
calls to GetRNGstate***" in the last sentence. That's why I'm suspecting I
have to use the method 2. Probably I have misunderstood this sentence.
Yongchao
More information about the R-help
mailing list