Skip to content
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

Fix poor randomness properties of first call to Rand.next(). #2321

Merged
merged 1 commit into from
Nov 16, 2017
Merged

Fix poor randomness properties of first call to Rand.next(). #2321

merged 1 commit into from
Nov 16, 2017

Conversation

EpicEric
Copy link
Contributor

@EpicEric EpicEric commented Nov 2, 2017

The current implementations of XorOshiro128Plus and XorShift128Plus return the sum of input seed values for the first value, which is unsafe. Rather than telling people to discard the first value, skip past it in the actual implementation.

This commit also fixes the documentation of current implementations for consistency with the Random trait.

Resolves #2320

@SeanTAllen SeanTAllen requested a review from sylvanc November 4, 2017 16:56
_y = y xor x xor (y >> 18) xor (x >> 5)
_x = y
x = x xor (x << 23)
_y = x xor y xor (x >> 18) xor (y >> 5)
Copy link
Member

@jemc jemc Nov 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm a bit slow to review this - can you explain this part of the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I commited this part by accident. I'm reverting it in the new squash.

The current implementations of XorOshiro128Plus and XorShift128Plus
return the sum of input seed values for the first value, which is
unsafe. Rather than telling people to discard the first value,
skip past it in the actual implementation.

This commit also fixes the documentation of current implementations
for consistency with the Random trait.

Resolves #2320
@jemc jemc changed the title Run next() for uninitialized Random values Fix poor randomness properties of first call to Rand.next(). Nov 16, 2017
@jemc jemc added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Nov 16, 2017
@jemc jemc merged commit 0785ebd into ponylang:master Nov 16, 2017
ponylang-main added a commit that referenced this pull request Nov 16, 2017
@jemc
Copy link
Member

jemc commented Nov 16, 2017

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Seed advice for Rand is not good
2 participants