-
Notifications
You must be signed in to change notification settings - Fork 431
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
Document dependency between streams in PCG64 #907
Comments
Good points; I made some changes to the book in this regard but the API documentation warrants review too. A secondary point is that on 32-bit platforms we currently use PCG32 with streams in |
That's dangerous. There's a reason why nobody in the last decades ever considered (OK, except Melissa O'Neill) creating "streams" using the constant part of an LCG, and it's that people realized very early that it doesn't work (see, e.g., https://ieeexplore.ieee.org/document/718715). |
I wonder about the best way to fix this. Maybe remove the stream parameter in a breaking release? (Deprecating is tricky, because we would have to deprecate |
@vks I don't see any point hacking PCG to "fix" this. Sure, PCG has single-stream variants, but since one of the biggest reasons to use non-crypto RNGs is to allow multiple generators without hitting memory usage/bandwidth/cache too hard, a 64-bit generator without streams is not so useful. I'm also a bit concerned about this limitation (which is to do with the state, not the stream). Therefore we should consider replacing PCG for use in |
Due to close correlations of PCG streams (rust-random#907) and lack of right-state propegation (rust-random#905), the `SmallRng` algorithm is switched to xoshiro{128,256}++. The implementation is taken from the `rand_xoshiro` crate and slightly simplified. Fixes rust-random#910.
Due to close correlations of PCG streams (rust-random#907) and lack of right-state propagation (rust-random#905), the `SmallRng` algorithm is switched to xoshiro{128,256}++. The implementation is taken from the `rand_xoshiro` crate and slightly simplified. Fixes rust-random#910.
Due to close correlations of PCG streams (rust-random#907) and lack of right-state propagation (rust-random#905), the `SmallRng` algorithm is switched to xoshiro{128,256}++. The implementation is taken from the `rand_xoshiro` crate and slightly simplified. Fixes rust-random#910.
The documentation of the PCG generators with a "stream" parameter does not state explicit that different streams generate independent sequences, but the existence of a parameter named "stream" implies somehow the idea.
The user should be made aware that the stream parameter is almost useless from a mathematical and statistical viewpoint.
Changing constant (stream) to an LCG with power-of-two modulus and a constant like the one used in PCG simply adds a constant to the sequence (more precisely, there are two equivalence classes of constants, and in each equivalence class the sequences are identical, except for an additive constant).
The minimal scrambling done by the generator cannot cancel this fact, and as a result changing the constant is basically equivalent to changing the initial state. You can try to run this program:
You can change state as you like, and the two constants c and d_ as you like. The program will set up two initial states so that the sequences generated by the two PRNGs are based on almost identical underlying LCG sequences, in spite of having arbitrary constants (stream parameters). I don't know how to write in binary in Rust, but I passed the output through this simple C program
and then through PractRand. If you comment one of the
println!
, everything is fine. If you interleave the two generators:You can also offset one of generator by hundred of iterations, but the sequences are so correlated that the result won't change.
I think the reader should be made aware of the danger. If you start several generators of this kind the state is too small to guarantee that there will be no overlap. Once you get overlap, since there are in practice just two sequences, you will get a lot of unwanted correlation.
The text was updated successfully, but these errors were encountered: