Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ RGBGibbsPriorFilter<TInputImage, TClassifiedImage>::GibbsTotalEnergy(int i)
if (changeflag)
{
difenergy = energy[label] - energy[1 - label];
const double rand_num{ rand() / 32768.0 };
const double rand_num{ rand() / (RAND_MAX + 1.0) };
Copy link
Contributor Author

@N-Dekker N-Dekker May 14, 2025

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Context of this pull request:

const double rand_num{ rand() / 32768.0 };
double energy_num{ std::exp(static_cast<double>(difenergy * 0.5 * size / (2 * size - m_Temp))) };
if (rand_num < energy_num)
{
m_LabelledImage->SetPixel(offsetIndex3D, 1 - label);
}

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.

double energy_num{ std::exp(static_cast<double>(difenergy * 0.5 * size / (2 * size - m_Temp))) };
if (rand_num < energy_num)
{
Expand Down
Loading