Posted 27 May 2015 - 10:51 PM
In vanilla lua, before generating a random number you have to use math.randomseed(os.time()) In order to stop from generating the same random number over and over again. The main problem with this is that if you are generating 50 random numbers in a row in say a for loop, they will all be the same because in the time it takes to generate all of them os.time() does not change. However, in computercraft, if you do something like
P.S. We have a stackexchange tag now :D/>
for i=1, 50 do
print(math.random(1,2))
end
All the random number will be different, which is not the case in regular lua, as I explained. How does computercraft achieve this? I looked through the source and could not find any redefinition of math.random (At least in the lua section) yet it seems to work differently. How is this achieved, and how can I do it in vanilla lua?P.S. We have a stackexchange tag now :D/>
Edited on 27 May 2015 - 08:51 PM