Skip to content

Commit a322eaa

Browse files
committed
Describe the behavior of cpp11 w/e random number generation
Fixes #27
1 parent a446257 commit a322eaa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vignettes/converting.Rmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,10 @@ return as_tibble(x, ".rows"_nm = num_rows, ".name_repair"_nm = name_repair);
154154
cpp11 defines a compatible but different version of the Rboolean enum.
155155
This means that you must ensure that at least one cpp11 header is included _before_ any R headers.
156156
One easy way to ensure this is to replace `#include <Rinternals.h>` with `#include <cpp11/R.hpp>`.
157+
158+
## Random Number behavior
159+
160+
Rcpp unconditionally includes calls to `GetRNGstate()` and `PutRNGstate()` before each wrapped function.
161+
This ensures that if any C++ code calls the R API functions `unif_rand()`, `norm_rand()`, `exp_rand()` or `R_unif_index()` the random seed state is set accordingly.
162+
cpp11 does _not_ do this, so you must include the calls to `GetRNGstate()` and `PutRNGstate()` _yourself_ if you use any of those functions in your C++ code.
163+
See [R-exts 6.3 - Random number generation](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Random-numbers) for details on these functions.

0 commit comments

Comments
 (0)