2
I’ve been programming Lua for a long time, but I’ve almost never had to work with math.randomseed
, I searched and found nothing informing about it, did some testing and none worked as I expected. The function math.randomseed
changes the value of the math.random
, but needed this Seed to be altered only inside a body do
and as I came out of it back to its previous value, I know the pattern is os.time()
, but in the code the Seed can be changed to any other.
Example:
math.randomseed(10) --> não tenho acesso a essa parte do código
do --> parte do código que tenho acesso
math.randomseed(50)
...
end --> até aqui a seed teria q ser 50
--> aqui a seed teria que voltar a ser 10
I made a code:
math.oldrandomseed = math.randomseed
math.randomseed = function(seed)
math.seed = seed
math.oldrandomseed(seed)
end
so you would know what the previous issue was, but you would have to have access to the outside of the code in order to execute it at the beginning (outside the do
), The point is, there’s some way to do this without leaving the do
?
Unable to recover to Seed. What real problem are you trying to solve with this?
– lhf
I was creating a function that would need to use the
math.randomseed
but did not want to "spoil" the code already running, because the person could be usingmath.randomseed
somewhere– Vinícius