Which would be more Efficient?

Just a Simple Question, What would be more efficient to use?

-- this is just 'math.random' usages
-- I was wondering what would be better to use
-- As the following do the exact same thing:

a = math.random(1, #tab) -- using both min and max Arguments

b = math.random(#tab) -- using only 1 argument (same as a)

Are they the exact same?

1 Like

There would literally be no difference. But I’d choose “a” since it’s readability is better. Other than that there is nothing to compare between these two.

This is like asking if task.wait(),time() is more efficient than wait(). They’re very similar, but presumably the 2nd one is more efficient since it contains less arguments.

Its actually os.clock(), not time().

You could also say ElaspedTime() would be similar (which it is), but thats been superseded by os.clock() (at least according to Roblox)

time() exists but it includes throttling. wait() also includes throttling. task.wait() is like wait() but it does not include throttling. This makes wait() a balance; it is not as accurate, but it will slow down if load is put on the game server (which might be more efficient in some cases). wait() will return two values, and the 2nd one is the elapsed game time which is equivalent to workspace.DistributedGameTime or time().

For something like this, the difference is so miniscule that it probably doesn’t matter. I would choose the 2nd one to remove unneeded arguments though.