[Rcpp-devel] RNGScope, importing function, and if-else statement

Davor Cubranic cubranic at stat.ubc.ca
Mon Apr 16 07:11:54 CEST 2012


At Sun, 15 Apr 2012 19:01:30 +0100, Marie Auger-Methe wrote:
> I want to use a random generator that is not available in the Rcpp:
> rvm from R's CircStats package and I want the number generated to be
> the same as the equivalent function in R. Importing the function
> within a Rcpp inline function works fine except if you have an
> if-else statement. The strange thing is that it works as long at the
> if-statement is TRUE, and then it doens't work anymore and some
> numbers are repeated but not in the same order.

In this example, it looks to me that the key is that as soon as you
start using 'vmc', the numbers get out of order. If that's the case,
then perhaps 'vmc' and 'runif' somehow both use the random seed, but
RNGScope keeps track only of 'runif's?

Davor


More information about the Rcpp-devel mailing list