Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Dirk Eddelbuettel
On 1 September 2011 at 17:35, Zhongyi Yuan wrote: | On Thu, Sep 1, 2011 at 2:35 PM, Dirk Eddelbuettel wrote: | | Please do not abuse this list as a substitute for doing your independent | study and reading. | | Thanks Dirk and sorry for causing such feeling. That makes me guilty. Really

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Zhongyi Yuan
On Thu, Sep 1, 2011 at 2:35 PM, Dirk Eddelbuettel wrote: > > Please do not abuse this list as a substitute for doing your independent > study and reading. > Thanks Dirk and sorry for causing such feeling. That makes me guilty. Really hesitated before I asked... Zhongyi > > Dirk > > > | Zhongy

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Zhongyi Yuan
Dave, Thanks for the reply. A few months ago I did not know this list yet... I think Dirk's way of simply setting a seed in R works for me. Your way seems to be a bit complicated for me. Maybe I am missing something. Will look closer... Zhongyi On Thu, Sep 1, 2011 at 2:45 PM, Silkworth,David J.

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Silkworth,David J.
RNGScope() mearly saves the state of the RNG for the R environment, returning it upon class destruction at end of your (compiled) Rcpp function. You can pass a seed to your Rcpp function as an argument and, after preserving state with RNGScope(), you can set the seed within the Rcpp function for t

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Dirk Eddelbuettel
On 1 September 2011 at 14:23, Zhongyi Yuan wrote: | If there is a seed set in R before rngs() is called, then "RNGScope z;" can be | omitted, right? Don't think about it this way. Think about properly initializing the state of the RNG, and instantiating a local RNGScope variable does that. Which

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Zhongyi Yuan
If there is a seed set in R before rngs() is called, then "RNGScope z;" can be omitted, right? I used to use RNGScope() to set seed. I guess that is not the right way, is it? My test shows, with RNGScope(), even if I re-compile (without quitting R), rngs always gives the same numbers. I have to q

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Zhongyi Yuan
Thank you for the quick reply, Dirk. Zhongyi On Thu, Sep 1, 2011 at 12:13 PM, Dirk Eddelbuettel wrote: > > On 1 September 2011 at 12:06, Zhongyi Yuan wrote: > | Hello everyone, > | > | I am conducting some numerical studies that I want to be repeatable. In > other > | words, I want others who r

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Dirk Eddelbuettel
I should have written that quick function as follows: rngs <- cxxfunction(signature(), plugin="Rcpp", body="RNGScope z; return Rcpp::rnorm(5,0,1);") You _do_ want RNGScope around; my bad for omitting it in the previous post. Dirk -- Two new Rcpp master classes for R

Re: [Rcpp-devel] repeatable random numbers

2011-09-01 Thread Dirk Eddelbuettel
On 1 September 2011 at 12:06, Zhongyi Yuan wrote: | Hello everyone, | | I am conducting some numerical studies that I want to be repeatable. In other | words, I want others who run my code to get exactly the same result as I get. | This can be easily done in pure R. | | But since I want the rand