So to my understanding math.random()
generates a pseudo random number, but if you use math.randomseed(tick())
you can simulate “true” random. I’ve heard that math.random()
is either deprecated or is going to be in the near future. I’ve also heard that math.random()
was updated to use the same algorithm as Random.new()
.
It probably doesn’t matter which method I use in all honesty but I want my project to be as optimized as possible.
What I’m looking for:
I need to have a system that generates random events. It’s crucial that the chances are as random as possible for gameplay reasons.
Which method should I go with?
math.random() Method:
math.randomseed(tick())
local randomNumber = math.random(1,100)
if randomNumber >= 50 then
-- Do the thing
else
-- Don't do the thing
end
-- 50% chance of doing the thing
Random.new() Method:
local randomNumber = Random.new():NextNumber(1,100)
if randomNumber >= 50 then
-- Do the thing
else
-- Don't do the thing
end
-- 50% chance of doing the thing