Skip to content

Commit fc8ebec

Browse files
authored
Merge pull request #825 from RcppCore/rng-state
unconditionally get/put RNG state
2 parents bc910d7 + 4934012 commit fc8ebec

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-02-26 Kevin Ushey <[email protected]>
2+
3+
* src/api.cpp: Always set / put RNG state when calling Rcpp function
4+
5+
16
2018-02-25 Dirk Eddelbuettel <[email protected]>
27

38
* vignettes/Rcpp.bib: Updated

inst/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
\section{Changes in Rcpp version 0.12.16 (2018-03-xx)}{
77
\itemize{
88
\item Changes in Rcpp API:
9+
\itemize{
10+
\item Rcpp now sets and puts the RNG state upon each entry to an Rcpp
11+
function, ensuring that nested invocations of Rcpp functions manage the
12+
RNG state as expected
13+
}
914
\itemize{
1015
\item The \code{long long} type can now be used on 64-bit Windows (Kevin
1116
in \ghpr{811})

src/api.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,17 @@ using namespace Rcpp;
6464
namespace Rcpp {
6565

6666
namespace internal {
67-
namespace {
68-
unsigned long RNGScopeCounter = 0;
69-
}
7067

7168
// [[Rcpp::register]]
7269
unsigned long enterRNGScope() {
73-
if (RNGScopeCounter == 0) GetRNGstate();
74-
RNGScopeCounter++;
75-
return RNGScopeCounter;
70+
GetRNGstate();
71+
return 0;
7672
}
7773

7874
// [[Rcpp::register]]
7975
unsigned long exitRNGScope() {
80-
RNGScopeCounter--;
81-
if (RNGScopeCounter == 0) PutRNGstate();
82-
return RNGScopeCounter;
76+
PutRNGstate();
77+
return 0;
8378
}
8479

8580
// [[Rcpp::register]]

0 commit comments

Comments
 (0)