That script uses the RandomIntMax() function to generate the seed on line #616. I don’t know if this function is subject to the same limitations as random().
Anyway, if the seed is always the same, the generated map objects will always be the same as well.
crate_seed = {763261} --seed used for random functions for crates, this should be the one and only instance of the default random() function being called
I think in this case they created a sync error safe random seed that all players synchronize. It doesn’t generate the same pseudo random sequence each game from what I have seen like the normal random does, my theory is that it is hard coded to the game tick clock or some other mechanism to prevent sync errors in multiplayer.
It seems very odd to have a specific random seed otherwise
Look again at line #616. The initial value you pointed out is overwritten at this spot. And it uses the RandomIntMax() function to do so. So, no, there is no special anti-desync behavior occurring here.
I haven’t looked at this since I first went through the files… my_seed is the important one. my_seed is not redefined which is what controls locations, spawn rate and rewards and RU’s, it looks like the crate_seed is only used to find a displacement from each mothership and then the my_seed is used to actually place it and determine contents.
edit: the srandom function has this header
--Global variables used for the seeded random functions, below.
seedobja = 1103515.245
seedobjc = 12345
seedobjm = 4294967.295 --0x100000000
> --Works like random(), except you provide your own seed as the first argument.
> --The results are that maps appear the same each time you run the game, but desyncs may possibly be avoided.
function srandom(seedobj, fVal1, fVal2)
seedobj[1] = mod(seedobj[1] * seedobja + seedobjc, seedobjm)
local temp_rand = seedobj[1] / (seedobjm - 1)
if (fVal2) then
return floor(fVal1 + 0.5 + temp_rand * (fVal2 - fVal1))
elseif (fVal1) then
return floor(temp_rand * fVal1) + 1
else
return temp_rand
end
end
However it will still pass the specific random seed from my_seed to srandom and from what I can determine it will never change values unless the min and max change, essentially in the above function temp_rand would just be a constant (unless they are relying on precision errors?) Which would mean the at the srandom function wouldn’t generate a random number?
I’m not certain why they would have two random values anyway
When I originally rewrote the crates script, I only used one seed for all the crates stuff. Not sure why Gearbox/beghins changed that.
And you are correct, srandom will always produce the same values each time the game is started.
I don’t think this behavior is what the other map makers want however (or maybe it is). I think they want completely random settings each time a map is hosted. For that, you need to randomize the seed using random() or RandomIntMax().
Relics have different logic which is interesting in itself, they use the total value of player RU’s at the given time as a pseudo random number for the position coordinates
function RandomRUBased(value)
randomsimulator = randomsimulator + 1
if randomsimulator >= 10 then
randomsimulator = 2
end
local val = 0
for playerIndex = 0,Universe_PlayerCount()-1,1 do
if Player_IsAlive(playerIndex) == 1 then
val = val + Player_GetRU(playerIndex)
end
end
while val > value do
val = floor(val / randomsimulator)
end
if val < 1 then
val = 1
end
if val >= 1 then
return val
end
end