I think you want to move the RNGScope declaration before the calls to rcauchy and runif.
On Tue, Aug 14, 2012 at 9:17 AM, Rodney Sparapani <rspar...@mcw.edu> wrote: > This is my first post so please be gentle ;o) I have been through > all of the docs that I can find (but I haven't looked at the source > code directly). Here is the behavior that I see: > >> require(inline) > Loading required package: inline >> source("helper.R") >> source("corrMH.R") >> >> set.seed(66) >> >> for(i in 1:3) print(corrMH(0.2, 0.5, 100, 0)) > [1] -0.07071726 > [1] -8.085111 > [1] -4.004675 >> >> corrMH.Rcpp <- cxxfunction( > + signature(a="numeric", b="numeric", N="numeric", x="numeric"), > + body=cat.file("corrMH.Rcpp.cpp"), plugin="Rcpp") >> >> set.seed(66) >> >> for(i in 1:3) print(corrMH.Rcpp(0.2, 0.5, 100, 0)) > [1] -0.07071726 > [1] -0.07071726 > [1] -0.07071726 > > Notice that the Rcpp version of the function returns the same value > each time (only 3 shown, but this is true no matter how many times > that you do it). I guess this is because we follow the RNGScope state > of the RNG, but we don't update it. However, updating is really needed > in this case. I hope I am making this clear. Please let me know if > you have any ideas. Thanks > > Attachments seem to be allowed so I'm including my code... > > Red Hat Enterprise Linux Server release 6.2 (Santiago) > g++ (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3) > R version 2.14.2 (2012-02-29) > >> installed.packages()["Rcpp", ] > Package LibPath > "Rcpp" "/opt/local/lib64/R/library" > Version Priority > "0.9.10" NA > Depends Imports > "R (>= 2.12.0), methods" NA > LinkingTo Suggests > NA "RUnit, inline, rbenchmark" > Enhances OS_type > NA NA > License Built > "GPL (>= 2)" "2.14.2" > -- > Rodney Sparapani, PhD Center for Patient Care and Outcomes Research > Sr. Biostatistician http://www.mcw.edu/pcor > 4 wheels good, 2 wheels better! Medical College of Wisconsin (MCW) > WWLD?: What Would Lombardi Do? Milwaukee, WI, USA > > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel