When does using RNGScope make a difference?

后端 未结 2 1850
予麋鹿
予麋鹿 2020-12-16 23:28

In Rcpp documentation, I often find the recommendation to place Rcpp::RNGScope scope; before using random draws within Rcpp. I wondered what exactly this does,

2条回答
  •  春和景丽
    2020-12-17 00:14

    This all becomes a little clearer once you read the original documentation in the Writing R Extensions manual, Section 6.3, "Random Numbers".

    All that RNGScope scope does is the automagic calls to "get" and "put" in order to keep the state of the RNG sane.

    The problem with your test code, as explained by Kevin, is that it already happens for you. So you can only test by going through .Call() by hand, in which case you will for sure leave the RNG in a mess if you use it and do not get/put properly.

提交回复
热议问题