BUG: Fix random number in RGBGibbsPriorFilter::GibbsTotalEnergy#5350
Merged
thewtex merged 1 commit intoInsightSoftwareConsortium:masterfrom May 15, 2025
Merged
Conversation
The original division of `rand()` by `32768.0` was probably meant to yield a number between `[0, 1>`. However, `rand()` returns an integer between `[0, RAND_MAX]`, and `RAND_MAX` may not be `32767`. In practice, when using GCC, `RAND_MAX` may be as large as `2147483647. The "magic number" `32768.0` was introduced on 12 Jan 2002 already, with commit 074c74f.
Contributor
Author
|
@chentingpc Hi Ting Chen! Could it be that this is originally your code? If so, maybe you can have a look at this pull request! 😃 |
N-Dekker
commented
May 14, 2025
| { | ||
| difenergy = energy[label] - energy[1 - label]; | ||
| const double rand_num{ rand() / 32768.0 }; | ||
| const double rand_num{ rand() / (RAND_MAX + 1.0) }; |
Contributor
Author
There was a problem hiding this comment.
On Windows, using MSVC/Visual Studio 2022, RAND_MAX + 1.0 is exactly 32768.0, but on Linux, using GCC, RAND_MAX + 1.0 may be 2147483648.0.
Contributor
Author
There was a problem hiding this comment.
Context of this pull request:
So this rand_num is a random threshold for energy_num. On Linux + GCC, the numbers returned by rand() are usually much higher than on Windows + MSVC. So on Linux + GCC, the threshold will be much higher, making it less likely that the if (rand_num < energy_num) clause will be entered.
thewtex
approved these changes
May 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The original division of
rand()by32768.0was probably meant to yield a number between[0, 1>. However,rand()returns an integer between[0, RAND_MAX], andRAND_MAXmay not be32767. In practice, when using GCC,RAND_MAXmay be as large as2147483647.The "magic number"
32768.0was introduced on 12 Jan 2002 already, with commit 074c74f.