You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DOC: clarification about what SeedSequence can and cannot do #25778
I want to be sure that what SeedSequence can and cannot do is clear from the doc. What I get from the doc is:
SeedSequence can create a good initial state even though I use 0 as my initial seed. This means that even if I use 0 as my seed I will not get any degenerate behavior from my RNG and the subsequent generated numbers will appear random and independent. Is this what is meant by SeedSequence can "ensure that low-quality seeds are turned into high quality initial states (at least, with very high probability)."?
The issue with using small seeds is that this is not covering the initial state space (even with SeedSequence) and therefore we might end up having people running studies with the same initial state which would create biases? So this is mainly to ensure that everyone is unique number?
Idea or request for content:
Maybe clarify what is meant by SeedSequence can "ensure that low-quality seeds are turned into high quality initial states (at least, with very high probability)", as it is also asked to provide large unique numbers for seeds.
Yes, that is the understanding we intended to convey. We go into detail about the problem being avoided in the subsequent paragraph. Without SeedSequence or some other conditioning of the seed (for instance, RandomState was already fine in this respect), 0 or 12345 would have made a bad single instance of MT19937 because of its zero-land properties. Similarly, 0x987...blahmanybitsblah...12345 and 0x987...blahmanybitsblah...12346 would have made a bad single pair of streams for any PRNG except for the weak-crypto ones like Philox.
The remaining issue with small seeds is twofold. First, people don't pull them randomly, even from the set of small integers. Instead, they use convenience seeds like 0, 10, 42, 12345, 31415926. These get repeated a lot.
Second, even if they did pull randomly from the set of small 32-bit integers and everyone got a unique 32-bit number, the space of 32-bit integers is small relative to the state spaces of modern PRNGs. Even without exact duplicates, there are biases with any particular 4294967296-sized subset of that state space. With SeedSequence and our recommended practice of secrets.randbits(128), we still have a default bottleneck of 128 bits, which is still smaller than our state spaces, but 128 bits is big enough that I don't care much about the remaining bias (and 128 bits is about the most I think I can get away with forcing people to copy-paste).
Item 2 is entirely orthogonal to Item 1. Our recommendation for big seeds is up in the Quick Start, where I don't really want to overwhelm people with too many details. We discuss Item 1 in the design section about SeedSequence where we can afford to go into details, but because the two issues are fairly orthogonal, I would not have thought to do so there. But I can see reading that discussion and coming away with the impression that SeedSequence dealt with all of the issues with small seeds. A small following note to say that we still recommend secrets.randbits(128) seeds for community practice reasons would probably be reasonable.
Thanks a lot @rkern for the explanation this is very clear! Yes I guess that for most users there is no need to get into that much details. I had overlooked the biases one would get with seeds smaller than the state space and hence the additional reason for having large seeds.
Activity
rkern commentedon Feb 6, 2024
Yes, that is the understanding we intended to convey. We go into detail about the problem being avoided in the subsequent paragraph. Without
SeedSequenceor some other conditioning of the seed (for instance,RandomStatewas already fine in this respect),0or12345would have made a bad single instance ofMT19937because of its zero-land properties. Similarly,0x987...blahmanybitsblah...12345and0x987...blahmanybitsblah...12346would have made a bad single pair of streams for any PRNG except for the weak-crypto ones likePhilox.The remaining issue with small seeds is twofold. First, people don't pull them randomly, even from the set of small integers. Instead, they use convenience seeds like
0,10,42,12345,31415926. These get repeated a lot.Second, even if they did pull randomly from the set of small 32-bit integers and everyone got a unique 32-bit number, the space of 32-bit integers is small relative to the state spaces of modern PRNGs. Even without exact duplicates, there are biases with any particular 4294967296-sized subset of that state space. With
SeedSequenceand our recommended practice ofsecrets.randbits(128), we still have a default bottleneck of 128 bits, which is still smaller than our state spaces, but 128 bits is big enough that I don't care much about the remaining bias (and 128 bits is about the most I think I can get away with forcing people to copy-paste).Item 2 is entirely orthogonal to Item 1. Our recommendation for big seeds is up in the Quick Start, where I don't really want to overwhelm people with too many details. We discuss Item 1 in the design section about
SeedSequencewhere we can afford to go into details, but because the two issues are fairly orthogonal, I would not have thought to do so there. But I can see reading that discussion and coming away with the impression thatSeedSequencedealt with all of the issues with small seeds. A small following note to say that we still recommendsecrets.randbits(128)seeds for community practice reasons would probably be reasonable.albertcthomas commentedon Feb 7, 2024
Thanks a lot @rkern for the explanation this is very clear! Yes I guess that for most users there is no need to get into that much details. I had overlooked the biases one would get with seeds smaller than the state space and hence the additional reason for having large seeds.
DOC: Added small clarification note. "Closes numpy#25778"
DOC: Added small clarification note, based on discussion in issue num…
DOC: Emtpy commit to run tests to close numpy#25778, [skip azp] [skip…
DOC: Added small clarification note, based on discussion in issue num…
Merge pull request #26357 from charris/backport-26340