A random question...

Monkey Forums/Monkey Programming/A random question...

ElectricBoogaloo(Posted 2013) [#1]
This isn't an issue, right now, but in the future, if I ever get online stuff happening, it might be.
Exactly how "Samey" is Monkey's Random number generator?
If I Seed=52;For n=1 To 1000;i=Rnd(0,50);Next, can I be absolutely sure that all targets are getting the same set of numbers, or are there quirks along the way that I need to be checking for?


Gerry Quinn(Posted 2013) [#2]
I am old-fashioned and don't trust floating point for such things!

I have a clone of the MSVC integer-based rand() function in the code section if you want it.


ElectricBoogaloo(Posted 2013) [#3]
I might just do that, thanks. Any further comments? Anyone?


Floyd(Posted 2013) [#4]
Ditto for the "don't trust floating point" attitude.

My favorite example of an unfathomable floating point bug comes from early days of Blitz3D, so long ago that the thread is no longer on the forums. Somebody had a simple calculation that was giving different results on different runs of his own PC. It was not even a question of different machines.

The answer turned out to be a change to FPU "mode", which affects the accuracy of floating point calculations. There is no way for Blitz3D to change the mode, but a DLL can do it. He was using one to capture in-game video. Floating point results changed depending on whether the video capture function had been used.