C++11 random number generators are consistent across platforms, but the distribution classes are not: http://stackoverflow.com/a/13589262

This commit is contained in:
David Williams
2015-02-10 23:35:17 +01:00
parent f87966686d
commit 7e19706681
2 changed files with 8 additions and 14 deletions

View File

@ -67,7 +67,6 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename Vol
// Set up a random number generator
std::mt19937 rng;
std::uniform_int_distribution<int32_t> dist(minValue, maxValue);
//Fill the volume with data
for (int32_t z = 0; z < iVolumeSideLength; z++)
@ -84,7 +83,9 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename Vol
else
{
// Otherwise we write random voxel values between zero and the requested maximum
typename VolumeType::VoxelType voxelValue = static_cast<typename VolumeType::VoxelType>(dist(rng));
// We can't use std distributions because they vary between platforms (breaking tests).
int voxelValue = (rng() % (maxValue - minValue + 1)) + minValue; // +1 for inclusive bounds
volData->setVoxelAt(x, y, z, static_cast<typename VolumeType::VoxelType>(voxelValue));
}
}