problem with radom and using os.time as seed

Using corona 1251, tested too in 1234. I can’t test my app in corona simulator…because i am using maps, it happens to me in Ios simulator

local function  roulette(event )     for i=1,#pointers do     pointers[i].alpha=0         pointers[i].target=0              end          math.randomseed( os.time()\*randomInc )     local seed=math.random(#pointers)     pointers[seed].alpha=1     pointers[seed].target=1 end  

randomInc is in a loop and increment its value …i added because with os.time didnt work…

values of os.time()*randomInc=423321093702,435771714420,448222334832…and so
seed value is always=1

EDIT:
the function roulette is called by a timer:
if the timer has a value of 1500 it works…
with 1000 the sequence of see var is:12345,12345,12345

300 always seed=1

Why is this? I need to understand it…

EDIT2

I am calling the roulette function inside a loop instead a timer and the result is the same ,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5… i really dont understand it… #pointers always has 5 elements created in createScene

EDIT3

removing “math.randomseed( os.time() )”

make it works …i thought it was better to add it
 

I hade lots of problem with getting veryrandom numbers but the following code at the beginning of mygame solved myproblem, hope it works for you too…

math.randomseed(system.getTimer())

Thanks mate, system.getTimer() works great os.time() dont…at least using storyboard…don’t know

You really only need to seed the random number generator once, unless you need to retrieve a certain sequence of numbers.  In most cases you do this at the beginning of the program.

I would advise against using system.getTimer() since it returns the time in milliseconds since the app launched.  Thus if you have it as line 3 of main.lua for instance, you are always going to get very close to the same value and potentially not be a random like seed.  

math.randomseed(os.time())

is the recommended way to do this.  But keep in mind this is granular to 1 second.  If you call randomseed right before you call math.random, you’re likely seeding the random number generator with the same value which means you’re going to get the same sequence of numbers at least until the next second when you would get a new sequence.

Try only seeding the generator once at the beginning of your main.lua

Rob

I hade lots of problem with getting veryrandom numbers but the following code at the beginning of mygame solved myproblem, hope it works for you too…

math.randomseed(system.getTimer())

Thanks mate, system.getTimer() works great os.time() dont…at least using storyboard…don’t know

You really only need to seed the random number generator once, unless you need to retrieve a certain sequence of numbers.  In most cases you do this at the beginning of the program.

I would advise against using system.getTimer() since it returns the time in milliseconds since the app launched.  Thus if you have it as line 3 of main.lua for instance, you are always going to get very close to the same value and potentially not be a random like seed.  

math.randomseed(os.time())

is the recommended way to do this.  But keep in mind this is granular to 1 second.  If you call randomseed right before you call math.random, you’re likely seeding the random number generator with the same value which means you’re going to get the same sequence of numbers at least until the next second when you would get a new sequence.

Try only seeding the generator once at the beginning of your main.lua

Rob