Synced or unsynced?
The random of synced is already given a randomised seed, this it taken care of by the engine.
os.time(), reading a file, etc... would anyway not be allowed in synced.
I don't know if this has been fixed, but the random seed of unsynced on the other hand wasn't well randomly initialised when I tried it. I tried to use os.time(), but because of rounding errors (seconds since 1970 is a huge number!), it only change every 10s or so.
Here's my little random init function I use for unsynced
Code: Select all
-- Call once at the start of the widget
local function BetterizeRandom()
local x,y=Spring.GetMouseState()
local BetterRand=math.floor(99*(os.clock()%99999)+(99*(os.time())%99999))+Spring.GetDrawFrame()+math.random(0,999)
for k=-5,BetterRand%100 do
math.random(0,999)
end
end
I don't know how much of it is useful, how much is wishful thinking, but it worked for me. The important bit is to use modulo, otherwise the small numbers get drowned in the rounding errors of the big ones.
I don't use randomseed, so that if random is already better randomised than my function can, then I won't lose such previous better randomisation. And if the previous random was super poor, then I at least would have randomised it amongst 100, which was good enough for my needs.
And again, this is for unsynced, don't worry about synced, the random seed of synced is already well randomised.