SmallRng uses wrong seed_from_u64 implementation#1203
SmallRng uses wrong seed_from_u64 implementation#1203dhardy merged 3 commits intorust-random:masterfrom
Conversation
There is discussion on this in #1038. I'm not really convinced it's worth introducing a breaking change for this. In any case, we make zero guarantees about compatibility of
This is a value-breaking change. We haven't merged breaking changes yet but probably will soon. |
|
I agree it's a bug, because |
|
@vks do you think it is reasonable to increase the tolerance of your normal distribution sparkline test here? |
|
@dhardy Sure, it seems the test failed only 0.4 % of the tolerance. I should probably calculate the probability of failing with the current tolerance to determine a better threshold. |
|
This still needs an update to the changelog and a fix for the tolerance of the test. |
|
I modified the test by feeding all the numbers in the range This means that 22/100 random seeds failed the unit test with error more than 3 standard deviations from expected. The other solution would ditch the truly obvious seed of 1 and pick a fair random number like 4 to move on. |
Thanks for investigating this! That's a much higher failure rate than what I would fundamentally expect for the 3 standard deviations threshold. I'll need to take a closer look at the error distribution. |
|
This only needs updating the changelog for 0.9, documenting the value-breaking change to |
dhardy
left a comment
There was a problem hiding this comment.
I check all merged PRs when writing changelogs anyway (we always miss some), so I can fix that then).
* Forward inner seed_from_u64 implmentation for SmallRng * increase tolerance of sparkline tests
Currently
SmallRngimplementsSeedableRngbut it does not specify aseed_from_u64method soSmallRnguses the default (pcg32) trait implementation. Because of this the Xorshiro'sseed_from_u64method using Splitmix64 is effectively dead code. Splitmix64 is recommended for seeding Xorshiro by opinionated people so this is definitely a bug.The documentation for
seed_from_u64says changing the algorithm is a "value-breaking change" but on the other hand the current implementation is a unintended bug so might not be protected from breaking changes.Should this wait for the next breaking version or be merged immediately?