Moon randomseed to function only within a body (of)

2

I've programmed Lua a long time, but I almost never had to work with math.randomseed , I researched and found nothing to report it, I did some testing and none worked as I expected. The math.randomseed function changes the seed value of math.random , but I needed this seed to be changed only within a do body and when I exited it it would return to the previous value, I know that the default is os.time() , but in the seed code 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 which seed was the previous one, but it would have to have access to the outside of the code in order to execute it at the beginning (outside do ), the question is: Is there any way to do this without leaving do ?

    
asked by anonymous 27.07.2016 / 00:53

0 answers