About randomseed

It’s not really a bug - the random number generator will generate a different set of numbers depending on the type of device it is run on, as it uses the native random number functions of each device.

This library should do the trick:

http://developer.coronalabs.com/code/portable-seedable-random-number-generator

[import]uid: 93133 topic_id: 33108 reply_id: 131744[/import]

“depending on the type of device it is run” ok but why it generates ALWAYS different number ON THE SAME device when using RANDOMSEED as I asked on my first question !? [import]uid: 107239 topic_id: 33108 reply_id: 131752[/import]

I guess that is broken then, in the meantime while you wait for it to be fixed (could be anywhere between a day and several ice ages with Corona) use the library I posted instead of the built in function. [import]uid: 93133 topic_id: 33108 reply_id: 131753[/import]

That’s right :slight_smile: thanks for the link, it should save me for now! [import]uid: 107239 topic_id: 33108 reply_id: 131761[/import]

Just a quick reference to what is going on.

If you do not seed the random number generator, math.random will grab the content from it’s seed variable and use it.

If you run your app in the simulator, that seed variable will likely contain whatever data last occupied that memory location and you get the illusion that you’re getting different numbers. When you do this on a device, there is a very good likelyhood that the contents of memory will be zeroed out and thus math.random gets seeded with 0 each time, producing the same sequence of random numbers.

I can’t confirm this, but it’s a reasonable concept.

Therefore if you want to make sure you get different numbers every time, you need to do what Peach said above and use

math.randomseed(os.time())

However, if you want the same sequence of numbers over and over, you need to pass a specific integer value to math.randomseed().

If that does not produce the same sequence over and over, it’s likely a bug. [import]uid: 19626 topic_id: 33108 reply_id: 131767[/import]