[Resolved] is math.random broke?

I am using math.random in two of my apps, and have noticed that it works perfect in the Corona Simulator, however uses the same sequence every time the app restarts when deployed to iOS.

Any ideas? [import]uid: 62706 topic_id: 29943 reply_id: 329943[/import]

You should probably seed the generator in your app to ensure a nice random sequence on every run:

Do this just once in main.cs before you use math.random():

 math.randomseed( os.time() )   

Note: I’m assuming you’re not seeding. If you are, then I think you might have a bug.

[import]uid: 110228 topic_id: 29943 reply_id: 120100[/import]

You’re right, I was not using a seed, works perfect now, thank you :slight_smile: [import]uid: 62706 topic_id: 29943 reply_id: 120107[/import]

The random function if unseeded probably uses a 32 bit uninitialized integer to seed itself. On the simulator it’s probably what ever was in those 4 bytes last giving you seemingly random values. But on device it’s always picking up 0 since the device is seemingly clearing memory for you.
[import]uid: 19626 topic_id: 29943 reply_id: 120272[/import]

You should probably seed the generator in your app to ensure a nice random sequence on every run:

Do this just once in main.cs before you use math.random():

 math.randomseed( os.time() )   

Note: I’m assuming you’re not seeding. If you are, then I think you might have a bug.

[import]uid: 110228 topic_id: 29943 reply_id: 120100[/import]

You’re right, I was not using a seed, works perfect now, thank you :slight_smile: [import]uid: 62706 topic_id: 29943 reply_id: 120107[/import]

The random function if unseeded probably uses a 32 bit uninitialized integer to seed itself. On the simulator it’s probably what ever was in those 4 bytes last giving you seemingly random values. But on device it’s always picking up 0 since the device is seemingly clearing memory for you.
[import]uid: 19626 topic_id: 29943 reply_id: 120272[/import]