Android Math.randomseed Results Different From Ios And Simulator?

Hello,

In my app I’m using the math.randomseed function to set up the pseudo-random number generator to generate a consistent series of random numbers based on an initial input, such that the random sequence will be the same if the same input is given later.

In my tests I am finding that for a given seed, the number sequences are correctly identical between the simulator and iOS (or at least on my iPad). But on Android, the same seed will yield a different number sequence. Is this a bug? Is there a workaround?

-- seed the random number generator: math.randomseed( 144 ) -- generate a random number: local random\_number = math.random() -- display the number: local txt = display.newText( tostring( random\_number ), 0, 0, native.systemFont, 16 ) txt.x = display.contentWidth / 2 txt.y = display.contentHeight / 2 -- Oddly, the result is 0.94144149261594 on iOS and simulator, but 0.2109288313477 on Android

Thanks for any insight!

Bobby

It’s not a bug - the sequence of random numbers is platform dependent.

Try this library which I’ve used when I need a repeatable sequence of numbers given a certain seed.

http://web-c2.anscamobile.com/code/portable-seedable-random-number-generator

Thank you so much for the reply! I had begun to surmise that the behavior of math.random might be defined as platform-dependent. It’s great to know about that platform-independent solution. Pretty nifty to feed the results of the crypto hash function back to itself recursively to generate random numbers.

I ended up going with some code I found here: https://love2d.org/forums/viewtopic.php?f=5&t=3424 which implements several cool pseudo-random algorithms including the Mersenne twister.

It’s not a bug - the sequence of random numbers is platform dependent.

Try this library which I’ve used when I need a repeatable sequence of numbers given a certain seed.

http://web-c2.anscamobile.com/code/portable-seedable-random-number-generator

Thank you so much for the reply! I had begun to surmise that the behavior of math.random might be defined as platform-dependent. It’s great to know about that platform-independent solution. Pretty nifty to feed the results of the crypto hash function back to itself recursively to generate random numbers.

I ended up going with some code I found here: https://love2d.org/forums/viewtopic.php?f=5&t=3424 which implements several cool pseudo-random algorithms including the Mersenne twister.