lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Majic wrote:
But if you're executing the script, in it's entirely, more than once a
second you're randomseed()'ing with the same time in that second and
you'll get the same random numbers...

Well if you're not able to have a "RunOnce"or "Init" function, then add this to your script:

if not Seeded then
 math.randomseed(os.time())
 Seeded = true
end

Unless you're also running each script in its own little sandbox without access to globals, in which case perhaps that is a problem..

You should know though that whilst each sequence of random() numbers are supposed to be random, no guarantee is given that two sequences from seeds that are very similar (ie differ by 1) won't share patterns. A fair few generators fail there (Delphi's math library comes to mind) - sometimes re-randomseeding with a random number produced by the sequence a few times can separate the seeds out a bit. Whether or not your C compiler suffers this, who knows. ie:

math.randomseed(os.time())
for i = 1,4 do
 math.randomseed(math.random(2^31))
end

It's every bit a hack as it looks too.

- Alex