Hey! I am still a learning scripter and I seek answers for my question. Is there a more efficient way to use math.random? that might sound confusing, but here’s my example:
local randomNumber = math.random(1,2)
if randomNumber == 1 then
-- code
end
if randomNumber == 2 then
-- code
end
-- is there a more efficient way of like going through the outcomes?
I wouldn’t replace math.random() with anything else but I know you can do something with math.min and math.max Why would you need another way of using math.random anyways?
There might be another way of doing it but I find this method the best. You could also make a table with the values that math.random generates then check from there.
The way you wrote it is neat and it’s what I would use.
Without a use case, you can’t get a proper answer to this question. The most efficient way to use math.random is to use it at all. Efficiency is now extending towards the system you’re putting math.random in, which is more important to analyse.
What’s your use case? What are you doing? An if statement can easily be better in one case and in another, may be worse or not even necessary at all. A use case is important to have for questions like this. If you don’t have one, then knowing what you’re trying to do is confusing and you end up with just a generalised this-or-that solution.