From 3f3a2deaa8534890939df24087dcd169a9049fb9 Mon Sep 17 00:00:00 2001 From: sorucoder <40341154+sorucoder@users.noreply.github.com> Date: Sun, 9 Dec 2018 00:58:05 -0500 Subject: [PATCH 1/4] Removed util.random, added util.randomFloat Removed util.random as it is a duplicate of math.random. Added util.randomFloat, which returns a random floating point number. --- sys/apis/util.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index 7d275a7..7638613 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -135,9 +135,9 @@ function Util.round(num, idp) return util.signum(num) * math.floor(math.abs(num) * mult + 0.5) / mult end -function Util.random(max, min) +function Util.randomFloat(max, min) min = min or 0 - return math.random(0, max-min) + min + return (max-min) * math.random() + min end --[[ Table functions ]] -- From 30640fd415e8b7d636bdc5995fd73275039d6eae Mon Sep 17 00:00:00 2001 From: sorucoder <40341154+sorucoder@users.noreply.github.com> Date: Sun, 9 Dec 2018 01:01:20 -0500 Subject: [PATCH 2/4] Fixed util.randomFloat Fixed if max is nil, that it behaves like math.random() --- sys/apis/util.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index 7638613..cc59848 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -137,6 +137,7 @@ end function Util.randomFloat(max, min) min = min or 0 + max = max or 0 return (max-min) * math.random() + min end From 2e94b61dff84886bdc30378a2e3a546c3a028dbe Mon Sep 17 00:00:00 2001 From: sorucoder <40341154+sorucoder@users.noreply.github.com> Date: Sun, 9 Dec 2018 01:04:24 -0500 Subject: [PATCH 3/4] Fixed util.randomFloat Fixed if both max or min is nil, it returns a number between 0 and 1 --- sys/apis/util.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index cc59848..b77d444 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -137,7 +137,7 @@ end function Util.randomFloat(max, min) min = min or 0 - max = max or 0 + max = max or 1 return (max-min) * math.random() + min end From eb8b8236744f9efde02d3d3838421ab735a31cb4 Mon Sep 17 00:00:00 2001 From: sorucoder <40341154+sorucoder@users.noreply.github.com> Date: Sun, 9 Dec 2018 14:52:52 -0500 Subject: [PATCH 4/4] Fixed util.signum --- sys/apis/util.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index b77d444..7f87230 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -132,7 +132,7 @@ end -- http://lua-users.org/wiki/SimpleRound function Util.round(num, idp) local mult = 10^(idp or 0) - return util.signum(num) * math.floor(math.abs(num) * mult + 0.5) / mult + return Util.signum(num) * math.floor(math.abs(num) * mult + 0.5) / mult end function Util.randomFloat(max, min)