Skip to content
Prev 58832 / 63424 Next

Seeding non-R RNG with numbers from R's RNG stream

Thank you Duncan and Gabriel.

I think that my trivial example was a little too trivial and is causing
some confusion. What's happening in the real function I'm writing is...

1. In R: Draw tens-of-thousands of times from a handful to Gamma RVs with
different parameters to initialize some variables. (Technically, I'm
calling gtools::rdirichlet which calls stats::rgamma)
2. Transfer the initialized variables to a function in C++
3. In C++: Draw millions of times from a Categorical(p) distribution, where
"p" is recalculated after each draw based on the current state of the RVs
in my system. (The heart of this is actually a Uniform(0,1) from the
 Xoshiro256+ generator as provided in the dqrng package.)
4. In R: post-process the results from the transformed space back to the
space of the parameters I'm estimating.
5. Still in R: call stats::runif to change the position in R's RNG stream
so that if the user calls the function 2 times in a row without setting the
seed, they'll still get pseudorandom results by providing the C++ RNG with
a different seed.

So, a single call to the user-facing function results in many many draws
from both RNG streams.

The true "problem" spawning my question is that I'd like my users to be
able to reproduce their results and calling set.seed() once seems more
"user friendly" than having them control two seeds, one with set.seed and
one with a seed argument. But I acknowledge that having the user have to
set both is the "safest" option.

My instinct is that the effects of this are so subtle as to not really be a
problem as you suggest, Duncan. But I am now thinking I'll need to
explicitly run some experiments to validate that.

I'm 100% in agreement about not reinventing the wheel, but instead relying
on the accumulated experience of the folks that are writing these RNGs.

Knowing more about the bigger use, does this still strike you as obviously
problematic?

Best,
Tommy

On Thu, Jul 30, 2020 at 4:49 PM Duncan Murdoch <murdoch.duncan at gmail.com>
wrote: