[added] some randomness helper functions to mathx

This commit is contained in:
Max Cahill 2021-05-04 11:41:22 +10:00
parent 7c975e8c4a
commit d9da4749e2

View File

@ -88,7 +88,26 @@ function mathx.smootherstep(v)
return v * v * v * (v * (v * 6 - 15) + 10)
end
--todo: various other easing curves
--todo: various other easing curves (bounce etc)
--randomness helpers
--(internal; use a provided random generator object, or not)
local function _random(_r, ...)
if _r then return _r:random(...) end
if love then return love.math.random(...) end
return math.random(...)
end
--return a random sign
function mathx.random_sign(_r)
return _random(_r) < 0.5 and -1 or 1
end
--return a random value between two numbers (continuous)
function mathx.random_lerp(min, max, _r)
return math.lerp(min, max, _random(_r))
end
--nan checking
function mathx.isnan(v)