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
Random.NextBytes is very slightly biased against 0xFF #41457
The Span<byte> version has the same effective implementation if Next() has not been overridden.
The problem is that InternalSample() returns values in the range [0, int.MaxValue) - that is, int.MaxValue is not included. This skews the distribution of possible values for bytes:
The catch is that I'm not sure that this is fixable, given that any fix for this would be a breaking change in the behavior, and we've been reluctant to do so for other parts of Random.
@GrabYourPitchforks - I mean, that issue is about the fact that there's a deviation in the algorithm used to generate what InternalSample() returns.
This one is more about how there's a slight bias due to the fact that InternalSample() doesn't return int.MaxValue. That is, even if there was no deviation in the algorithm, there would still be this issue.
Although yes, it may end up being a dupe due to the resolution. I just wanted this explicitly called out.
Ah, yes, you're right in that it's not an exact dupe. But the resolution would be the same. Either they're all resolved as "by design", or they're fixed all at once.
The fix implemented at this time only affects randoms created without an explicit seed. Due to compatibility concerns, randoms initialized with a seed retain the old behavior.
ghost locked as resolved and limited conversation to collaborators on Feb 20, 2021
Activity
Dotnet-GitSync-Bot commentedon Aug 27, 2020
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
GrabYourPitchforks commentedon Aug 27, 2020
Possible dupe of #23198.
Clockwork-Muse commentedon Aug 27, 2020
@GrabYourPitchforks - I mean, that issue is about the fact that there's a deviation in the algorithm used to generate what
InternalSample()returns.This one is more about how there's a slight bias due to the fact that
InternalSample()doesn't returnint.MaxValue. That is, even if there was no deviation in the algorithm, there would still be this issue.Although yes, it may end up being a dupe due to the resolution. I just wanted this explicitly called out.
GrabYourPitchforks commentedon Aug 31, 2020
Ah, yes, you're right in that it's not an exact dupe. But the resolution would be the same. Either they're all resolved as "by design", or they're fixed all at once.
Clockwork-Muse commentedon Jan 21, 2021
Note to future readers:
The fix implemented at this time only affects randoms created without an explicit seed. Due to compatibility concerns, randoms initialized with a seed retain the old behavior.