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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,8 @@ int32_t normal_random(int32_t minNumber, int32_t maxNumber)
v = normalRand(getRandomGenerator());
} while (v < 0.0 || v > 1.0);

std::tie(minNumber, maxNumber) = std::minmax(minNumber, maxNumber);
const int32_t diff = maxNumber - minNumber;
return minNumber + std::lround(v * diff);
auto&& [a, b] = std::minmax(minNumber, maxNumber);
return a + std::lround(v * (b - a));
}

bool boolean_random(double probability /* = 0.5*/)
Expand Down
Loading