If I create a simple lua script file:
test.lua
#!/usr/bin/env lua
local var = math.random(100)
print(var)
It will always print the same value when called, even though it really should be a new random value at each call.
My guess is that the script gets compiled(?) to for example:
#!/usr/bin/env lua
local var = 82
print(var)
(if 82 was the random value at first call)
What can I do to make sure that a new (?)bytecode gets compiled(?) each time I call the script, so that I can get a fresh random value at each execution of the script?
The reason I added the (?) is that I don’t even know if scripts get compiled at all or what happens to them when they are called, but something like that is clearly happening since I get the same value all the time.
Your script is not being kept as bytecode, it’s just that the same default random seed is used at every run. This has the effect you’re seeing: you get the same “random” sequence every time you run your script.
You should initialize it by doing, for example