Open
Conversation
So, if we pick a modulus of 0, of course uniform_1 croaks. If our generator really is acceptably random, that should be pretty rare. We add another call, which still doesn't guarantee we don't get two zeros in a row, but if that happens, the PRNG is more likely to be broken or your luck was really bad. We could just bitwise-or in a 1, but I prefer having this canary. As evidence that I have tested this code too infrequently without rdrand, it turns out that PCG32 initialization without rdrand has been quite weak, all this time, and it's quite common to get 0 from uniform32 here as the modulus, much more than it should have been.
Without rdrand, benchmarks were aborting because the first value generated was often zero. Having high-quality seeding has never been a goal of this library, but this was pretty bad. So we mix in an initialization constant (from some other code I wrote using pcg32, which presumably took it from upstream PCG examples or a similar source).
Merged
Contributor
|
FYI, I've tested these change and they seem fine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I clearly started renovating this a few years ago and then stopped. Probably should merge these changes, not that I think anyone still uses this library.