Random not random

Can someone help me understand how random() works.

If I use random(), I get the same sequence of numbers even after corona simulator has closed. Every execution of the similar is the exact same sequence.

If I create a new seed, it resets it. But without creating a new seed, it seems to always use the same number sequence even when the app is shut down and reset. I would think random would at least generate a new seed on each execution of the simulator.

It seems without using seed, it isn’t really random at all. I get some thing that look like it never even tried to random and it doesn’t change what so ever even stopping simulator and starting again. Add a seed, and it seems to act as I would expect. [import]uid: 160288 topic_id: 33529 reply_id: 333529[/import]

This is quite normal… this is how all programming languages work not just lua… usually you have to provide a randomseed… usually we utilise the current time

http://lua-users.org/wiki/MathLibraryTutorial [import]uid: 67619 topic_id: 33529 reply_id: 133290[/import]

Use this

math.randomseed(os.time())   

before you use random

but don’t use in a loop it will slow don you code [import]uid: 147488 topic_id: 33529 reply_id: 133296[/import]

That’s what I do in the beginning of main.lua. But I was under the impression it would be random without that, and each time you stop corona SDK it would have a new seed. I find it very odd that once you call random, it has the same random string for the life of the app no matter how many times you start/stop it and how many times you change the code (until you actually do go and set a new seed).

All the examples call random, and many of them don’t bother setting a random seed. [import]uid: 160288 topic_id: 33529 reply_id: 133297[/import]

Like I said before… this is normal behavior… not just for lua but for any other programming languages…
the function random in any language follows an algorithm to generate the required numbers… and every time you run it… it will give you the same numbers…

in every language you come across if you truly want a random number then you need to use the time seed… this is just the way it is… [import]uid: 67619 topic_id: 33529 reply_id: 133299[/import]

This is quite normal… this is how all programming languages work not just lua… usually you have to provide a randomseed… usually we utilise the current time

http://lua-users.org/wiki/MathLibraryTutorial [import]uid: 67619 topic_id: 33529 reply_id: 133290[/import]

Use this

math.randomseed(os.time())   

before you use random

but don’t use in a loop it will slow don you code [import]uid: 147488 topic_id: 33529 reply_id: 133296[/import]

That’s what I do in the beginning of main.lua. But I was under the impression it would be random without that, and each time you stop corona SDK it would have a new seed. I find it very odd that once you call random, it has the same random string for the life of the app no matter how many times you start/stop it and how many times you change the code (until you actually do go and set a new seed).

All the examples call random, and many of them don’t bother setting a random seed. [import]uid: 160288 topic_id: 33529 reply_id: 133297[/import]

Like I said before… this is normal behavior… not just for lua but for any other programming languages…
the function random in any language follows an algorithm to generate the required numbers… and every time you run it… it will give you the same numbers…

in every language you come across if you truly want a random number then you need to use the time seed… this is just the way it is… [import]uid: 67619 topic_id: 33529 reply_id: 133299[/import]