What is math.randomseed(tick()) used for? trying to benefit from this code.
From a computational perspective, “true” randomness is infeasible. Numbers can be made to look random however the next generated number is based on the last generated number. A generator that does this is called a pseudo-random number generator (PRNG). The numbers produced by these are not truly random. But the data used by this generator is called the seed.
By using math.randomseed
you can set the seed that will be used by the PRNG.
math.randomseed(1)
print(math.random())
print(math.random())
print(math.random())
print()
math.randomseed(1)
print(math.random())
print(math.random())
print(math.random())
My result:
0.94843442061922
0.061285879733742
0.8770159548057
0.94843442061922
0.061285879733742
0.8770159548057
In other words, you set the source of randomness via math.randomseed
and you can get from it using math.random
.
Since the result of tick()
varies from instance to instance it is perfect for seeding.
I’m not sure if I did my coding right but whenver I did math.randomseed(tick())
I was getting nil
. I attempted to add in a math.floor
but still was getting nil
.
I did try doing math.randomseed
using numbers like 1 and 21712837123 and was still getting nil
so it may just be an issue with my understanding of math.randomseed
probably because you are doing print(math.randomseed(tick())) instead of
math.randomseed(tick())
print(math.random())
because randomseed is setting the seed value to tick for your math.random to be different
#LateGang