Skip to content

Commit 8d36406

Browse files
committed
ammend RNG note
1 parent 0323c60 commit 8d36406

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

docs/last-updated.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"last_updated": "Last updated: 2025-11-29 20:43:17"
2+
"last_updated": "Last updated: 2025-11-30 09:25:47"
33
}

docs/search.json

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

docs/vignettes/08-logical-functions-2.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ <h2>Are all values in a vector ‘true’?</h2>
260260
all2_cpp_3(x &gt; 2)
261261
)</code></pre>
262262
</div>
263-
<div id="references" class="section level2">
264-
<h2>References</h2>
265-
</div>
266263

267264

268265

docs/vignettes/09-rolling-functions-2.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,6 @@ <h2>Cumulative maximum</h2>
286286
cummax_cpp(x)
287287
)</code></pre>
288288
</div>
289-
<div id="references" class="section level2">
290-
<h2>References</h2>
291-
</div>
292289

293290

294291

docs/vignettes/10-statistical-functions-2.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ <h2>Root Mean Square Error (RMSE)</h2>
249249
rmse2_cpp(x, 0, na_rm = TRUE)
250250
)</code></pre>
251251
</div>
252-
<div id="references" class="section level2">
253-
<h2>References</h2>
254-
</div>
255252

256253

257254

docs/vignettes/12-external-pointers.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ <h1></h1>
9797
return ptr;</code></pre>
9898
<p>Similarly, the <code>Rcpp</code> version checks the engine with:</p>
9999
<pre class="r"><code>stopifnot(inherits(engine, "tesseract"))</code></pre>
100-
<div id="references" class="section level2">
101-
<h2>References</h2>
102-
</div>
103100

104101

105102

docs/vignettes/13-compiler-optimization.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ <h2>Anticonf scripts</h2>
193193
optimization level used by R. It also serves the goal of testing that a
194194
simple file can be compiled.</p>
195195
</div>
196-
<div id="references" class="section level2">
197-
<h2>References</h2>
198-
</div>
199196

200197

201198

docs/vignettes/16-FAQ.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,26 @@ <h2>How do I modify a matrix rownames/colnames on C++ side?</h2>
692692
return out;
693693
}</code></pre>
694694
</div>
695+
<div id="how-do-i-use-the-same-seed-defined-in-r-for-random-number-generation-in-c" class="section level2">
696+
<h2>How do I use the same seed defined in R for random number generation
697+
in C++?</h2>
698+
<p>If you use <code>set.seed(42)</code> (or any other value) in R, you
699+
need to explicitly use <code>GetRNGstate()</code> and
700+
<code>PutRNGstate()</code> in your C++ code to synchronize the RNG state
701+
between R and C++. Otherwise, the result will not be replicable for not
702+
correctly using the Random Number Generator (RNG) state from R.</p>
703+
<pre class="cpp"><code>#include "cpp4r/doubles.hpp"
704+
#include "R.h"
705+
#include "Rmath.h"
706+
707+
// single draw from standard normal using R's RNG (replicable result)
708+
[[cpp4r::register]] double using_rng_() {
709+
GetRNGstate();
710+
double x = Rf_rnorm(0, 1);
711+
PutRNGstate();
712+
return x;
713+
}</code></pre>
714+
</div>
695715

696716

697717

0 commit comments

Comments
 (0)