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

Enhance the generation of random floating point by PCG #7842

Merged
merged 3 commits into from
Jun 8, 2023

Conversation

GHamrouni
Copy link
Contributor

The previously implemented method of creating a random integer then dividing it by std::numeric_limits<uint32_t>::max() results in a distribution that is not truly uniform.

A more robust method for generating a random floating number :
double d = ldexp(pcg32_random_r(&myrng), -32);

This is the method recommended in PCG documentation.

For further explanation why the existing approach yields suboptimal results here.

@GHamrouni
Copy link
Contributor Author

Fixed a unit test, relying on a particular seed value.

Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! LGTM

@GHamrouni
Copy link
Contributor Author

I'm glad to hear that the Pull Request looks good to you. If there are any additional changes needed, feel free to let me know.

@Mytherin Mytherin merged commit adaa4c9 into duckdb:master Jun 8, 2023
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants