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 normal_random behavior on negative parameters #4555

Merged
merged 1 commit into from
Oct 15, 2023

Conversation

ranisalt
Copy link
Member

Pull Request Prelude

Changes Proposed

When the algorithm was updated to avoid skew #4539 I accidentally broke passing negative numbers in reverse order (e.g. calling normal_random(-1, -100) instead of normal_random(-100, -1)) due to the way std::minmax works: it returns references to the minimum and maximum element, and combined with std::tie it would replace minNumber in-place before it's value was moved to maxNumber.

Storing the values in local variables fixes the problem without adding an explicit branch + swap as proposed in the comments.

Issues addressed: fixes #4554

@MillhioreBT MillhioreBT merged commit 16a985c into master Oct 15, 2023
20 checks passed
@MillhioreBT MillhioreBT deleted the fix-normal-random-negative branch October 15, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New random algorithm always return max number if negative
3 participants