1

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!

  • 1
    Do your devices have different word sizes? I think MT19937 generates different values on 32-bit vs. 64-bit systems. – Lynn May 11 '15 at 20:23
  • I'm currently using nokia lumia 920. I think it's a 32 bit cpu Snapdragon S4 MSM8960. Other device is iPad mini non retina and macbook pro 32 bit application running. – user3433660 May 11 '15 at 20:55
  • this post suggests another random generator: http://stackoverflow.com/a/9269526/3433660 . Is this cross platform safe? – user3433660 May 11 '15 at 22:10
  • @user3433660 That post is completely outdated and obsolete. Don’t use it. – Konrad Rudolph May 12 '15 at 10:11
  • @KonradRudolph could you explain why? It gives me some pretty nice results for my terrain with really cross platform independent values and works on all OS. – user3433660 May 13 '15 at 11:03
  • @user3433660 (1) It’s a bad random number generator. If it seems to give you nice results — fair enough. But beware that they are probably not as random as you think, and this may lead to weird artefacts (either sudden repetitive landscapes or whatever); or it may not: I have no idea, but it’s safer to simply use good random numbers rather than bad ones. It involves less luck. (2) the API. The C++11 random number API (though far from perfect) was designed to be easily composable with standard algorithms. The `CRnd` class you linked to, by contrast, has a non-standard (and simply terrible) API. – Konrad Rudolph May 13 '15 at 12:11

1 Answers1

0

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.

Community
  • 1
  • 1
mareko
  • 408
  • 5
  • 7