Same Rnd() on all targets?

Monkey Forums/Monkey Programming/Same Rnd() on all targets?

Midimaster(Posted 2013) [#1]
Is there a guarantee, that Rnd() produces the same row of numbers on all targts if I use the same Seed?

In a multiplayer game I need the same row of random numbers on all targets. The first player decide the "seed" and sends it to the other players. The seed is used to produce a row of 250 numbers needed in the game. Of course I must guarantee, that all targets use the same row of numbers.


programmer(Posted 2013) [#2]
Is there a guarantee
You could try to implement custom PRNG like http://en.wikipedia.org/wiki/Mersenne_twister

(edited)


Gerry Quinn(Posted 2013) [#3]
You could use this:

http://www.monkeycoder.co.nz/Community/posts.php?topic=1568#14494

- Gerry Quinn


ElectricBoogaloo(Posted 2013) [#4]
SpikeDislike2, Hoppy Bobby and BlastTrax all use static random seeds to generate their levels.
They appear to be generating identical levels on GLFW (Windows), iOS, Android and HTML5 targets.

99% workable, I'd say, but maybe add a small amount of checking, to be certain. Should be alright for most stuff.


Midimaster(Posted 2013) [#5]
Thank you for the responses... but I'm not yet searching for a replacement for the original function.

I would prefer not to add any third party code, but use the original function.

I only would like to know if anybody already made negativ experiences with Rnd(). Or somebody, who did already tests on this...


Xaron(Posted 2013) [#6]
It uses the same algorithm so I don't see why it should generate different results on different platforms.


Nobuyuki(Posted 2013) [#7]
Midimaster: If you check, the Rnd() function is based in pure monkey, and while it isn't very good at providing a "consistently random" distribution of values, it should produce consistent results across platforms. I say should, because I forget whether or not Shr is left up to the implementing platform as to whether it is an arithmetic shift. I believe an arithmetic right shift is forced on all platforms, since unsigned ints are not part of Monkey.

In fact, probably the main reason a better PRNG like mersenne twister wasn't used was due to this...


bazmonkey(Posted 2013) [#8]
Seems the same across the platforms I use (Flash, iOS, html5), but I did have this concern also.
I agree it would be nice to know officially if this is the case.


Gerry Quinn(Posted 2013) [#9]
What about machines with different floating point width?

My int-based rand() above would give different results on 64-bit platforms if I did not force the seed to a 32-bit value.

But as for using Rnd(), I haven't seen it but I simply didn't really trust a floating point randomiser that I didn't understand, and not long after I did this a bug came out in Rnd() though it has since been fixed... So I made a clone of the MSVC function which I knew was satisfactory.