1D Noise using Mersenne twister giving different r

2019-08-07 19:39发布

I'm generating 2D terrain with 1D perlin noise using Mersenne Twister to for random numbers. My first thought was using Mersenne Twister will give me always the same results with same seed on any given hardware. But when I compare the values/terrain on different devices it gives me different results. (It worked for IOS, OSX and MAC, but not for WP8).

Code:

class 1DNoiseTest
{
    typedef std::mt19937 MyRNG;
    MyRNG rng;
1DNoiseTest( unsigned seed )
    {
        rng.seed(seed);
        std::uniform_real_distribution<double> distribution(0.0,1.0);
        for ( unsigned i = 0; i < kMaxVertices; ++i )
        {
            r[ i ] = ( distribution(rng)); error
        }
    }

...

Am I misunderstanding Mersenne Twister or am I doing something wrong? How could I get the same terrain/values on every device/hardware?

Thanks for your time!

标签: c++ random srand
1条回答
\"骚年 ilove
2楼-- · 2019-08-07 19:53

See this question:

C++11 cross compiler/standard library random distribution reproducibility

std::uniform_real_distribution is not guaranteed to give same results across different compilers.

查看更多
登录 后发表回答