From 958a7065468cf7df2b4a0755eac926e3b3f0134a Mon Sep 17 00:00:00 2001 From: Xertis <118364459+Xertis@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:59:53 +0300 Subject: [PATCH] add new extensions.lua --- res/scripts/stdmin.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/res/scripts/stdmin.lua b/res/scripts/stdmin.lua index 76df31e2..56b11639 100644 --- a/res/scripts/stdmin.lua +++ b/res/scripts/stdmin.lua @@ -51,6 +51,19 @@ function math.rand(low, high) return low + (high - low) * math.random() end +function math.normalize(num, conf) + conf = conf or 10 + + return (num / conf) % 1 +end + +function math.round(num, places) + places = places or 0 + + local mult = 10 ^ places + return math.floor(num * mult + 0.5) / mult +end + ---------------------------------------------- function table.copy(t) @@ -91,6 +104,15 @@ function table.random(t) return t[math.random(1, #t)] end +function table.shuffle(t) + for i = #t, 2, -1 do + local j = math.random(i) + t[i], t[j] = t[j], t[i] + end + + return t +end + ---------------------------------------------- local pattern_escape_replacements = {