Closed a-day-old-bagel closed 6 years ago
It shouldn't do, let me look into it
I couldn't reproduce the issue, have you got any more details on how you encountered this?
I'll have to look again and see if I can find more details. I was using gcc on Linux and MSVC on Windows, but I'll try to isolate the cause. It could have just been my system or library versions or some random thing.
The cause of this issue seems to be that random number distributions algorithms are implementation-defined. See the discussion at https://www.reddit.com/r/cpp/comments/7i21sn/til_uniform_int_distribution_is_not_portable/. I was able to reproduce the issue on Linux with GCC 7 + libstdc++ vs. Clang 5.0 + libc++.
#include "FastNoise.h"
#include <iostream>
int main(int argc, char* argv[])
{
int mySeed = 42;
FastNoise myNoise;
myNoise.SetSeed(mySeed);
std::cout << "seed: " << myNoise.GetSeed() << "\n";
std::cout << "noise: ";
for (int x = 1; x < 6; ++x) {
for (int y = 1; y < 6; ++y) {
std::cout << " " << myNoise.GetNoise(x, y);
}
}
std::cout << "\n";
return 0;
}
This program prints different sequences, whether it is linked with libstdc++ (version (Debian 7.2.0-17) 7.2.1 20171205) or with libc++ (Debian package version 5.0-1). If I replace std::uniform_int_distribution with boost::random::uniform_int_distribution here: https://github.com/Auburns/FastNoise/blob/f8423d7b5fabea7630712bb13a3d43be36299f8f/FastNoise.cpp#L208, then the program will generate the same sequence, no matter what compiler and standard library were used.
I just put up a change removing use of std::uniform_int_distribution in favour of std::mt19937_64 and using modulo to get a range, while this isn't a uniform distribution it is using a uint64 so it is very very close. https://github.com/Auburns/FastNoise/commit/b7d77466ade85e2206d0b31e0dd5f20076cce6e6
I notice that I get different results for the same seed depending on whether I compile in Windows or Linux. Is this a concern?