Welcome to dqrng Discussions! #93
Replies: 3 comments 1 reply
-
|
I'm using dqrng and have found it useful. But, I have a question. |
Beta Was this translation helpful? Give feedback.
-
|
The dqset.seed function for the pcg64 random number generator has the form dqset.seed(seed, stream) where both seed and stream are integer vectors of length 2. A value for the seed vector can be obtained from the generateSeedVector function that relies on the seed to R's random number generator: e.g.,
These are negative numbers that are not allowed for pcg64 for example. So, what's happening? I believe this is a question of how you interpret bits in C++ and R. The C++ code for pcg64 was likely written using unsigned 64-bit integers. At least that's what the implementations I've seen do. A 64-bit unsigned integer can be viewed as two 32-bit unsigned integers and passed back to R where integers get only 32 bits of storage. But, R works with 32-bit signed integers using two's complement representation. Thus, the negative sign are likely from R's two's complement interpretation of the bit pattern for a C++ unsigned 32-bit integer. Am I right on this? Assuming I'm correct, cannot generateSeedVectors be used to set the stream as well. The only difference from setting the seed is that the stream constant (or lcg increment) needs to be odd. That can be fixed, I think, by ensuing that the least significant bit of the second vector component returned from generateSeedVectors is set to 1. Any comments/answers would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
|
Very nice. Thanks again. If you’re ever in Las Cruces NM I’ll buy you a beer (or beverage).
On Mar 18, 2025, at 3:21 PM, Ralf Stubner ***@***.***> wrote:
Your interpretation w.r.t. unsigned 64bit integers needed by PCG64 (and the other RNGs in the package) and R only supporting signed 32bit integers is correct. So you can use generateSeedVectors() also for the stream constant. And you don't have to care about the constant being odd, since the PCG implementation takes care of that, c.f. https://github.com/daqana/dqrng/blob/main/inst/include/pcg_random.hpp#L322.
—
Reply to this email directly, view it on GitHub <#93 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BQTUSQFFYZKH3XFGRLYR27T2VCE5FAVCNFSM6AAAAABUTFT4F2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENJUGM4TKNQ>.
You are receiving this because you commented.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
👋 Welcome!
We’re using Discussions as a place to connect with other members of our community. We hope that you:
build together 💪.
To get started, comment below with an introduction of yourself and tell us about what you do with this community.
Beta Was this translation helpful? Give feedback.
All reactions