using a local for math.random calls

This commit is contained in:
Paul Liverman III 2018-04-23 02:31:26 -07:00
parent 0980d07eaa
commit 78805a5e42

View File

@ -32,6 +32,7 @@ local math_ceil = math.ceil
local math_atan2 = math.atan2 or math.atan local math_atan2 = math.atan2 or math.atan
local math_sqrt = math.sqrt local math_sqrt = math.sqrt
local math_abs = math.abs local math_abs = math.abs
local math_random = math.random
local noop = function() local noop = function()
end end
@ -133,12 +134,12 @@ end
function lume.random(a, b) function lume.random(a, b)
if not a then a, b = 0, 1 end if not a then a, b = 0, 1 end
if not b then b = 0 end if not b then b = 0 end
return a + math.random() * (b - a) return a + math_random() * (b - a)
end end
function lume.randomchoice(t) function lume.randomchoice(t)
return t[math.random(#t)] return t[math_random(#t)]
end end
@ -213,7 +214,7 @@ end
function lume.shuffle(t) function lume.shuffle(t)
local rtn = {} local rtn = {}
for i = 1, #t do for i = 1, #t do
local r = math.random(i) local r = math_random(i)
if r ~= i then if r ~= i then
rtn[i] = rtn[r] rtn[i] = rtn[r]
end end
@ -677,7 +678,7 @@ end
function lume.uuid() function lume.uuid()
local fn = function(x) local fn = function(x)
local r = math.random(16) - 1 local r = math_random(16) - 1
r = (x == "x") and (r + 1) or (r % 4) + 9 r = (x == "x") and (r + 1) or (r % 4) + 9
return ("0123456789abcdef"):sub(r, r) return ("0123456789abcdef"):sub(r, r)
end end