-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Results from separate seed() and set_stream() differ from two-argument seed() #91
Comments
These methods have rather surprising properties, c.f. imneme/pcg-cpp#91. THis makes it impossible to get consistent results together with `clone(stream)`.
* Add clone(stream) method for the RNGs and don't use two argument constructor/seed method for PCG These methods have rather surprising properties, c.f. imneme/pcg-cpp#91. This makes it impossible to get consistent results together with `clone(stream)`. * Add template methods to the RNG class to draw from a distribution This new methods are also used where random variates are generated. The methods are inspired by Melissa O'Neill's `randutil`. Main adaption is that one needs to fully specify the distribution since the aliases dqrng::normal_distribution etc. are already fully specified. The original methods are also available.
The behavior you observe is normal. It is caused by the "conditioning" process used to randomize the seeds you give to PCG. Seeds are used to set the state of the linear congruential generator (LGC) that lies within PCG. The seeds, however, are not simply copied into the state variable. First, they are conditioned or stirred, a process which modifies them. The "conditioned" seed is what gets installed into the LCG.
state_ = (seed + increment()) * multiplier() + increment(); But increment() == (stream() << 1) | 1u; When you call pcg64 rng; // default constructor chooses "default" stream
rng.seed(20240409); // function `seed` stirs, using the default stream When you call
This explains why the resulting states are different. If you reverse the order, calling |
Thanks for the explanation. I am surprised by the order of the processes taken when |
There is a technical reason why the stream is set before the seed. It is because stream functions are implemented via a Now, you may be thinking, "What does construction have to do with calling function The short answer is this: When you call one of the For more detail, see Issue #94. |
When I seed and set the stream separately I get a different result than if I do that with a single call. Is that expected?
Example code:
Output:
I would have expected the second and third line to be identical. While that is true for the stream indicator (second number), this is not the case for the RNG state (third number).
The text was updated successfully, but these errors were encountered: