From 5a43936e359e1d4029802b0618057bb18e7416c9 Mon Sep 17 00:00:00 2001 From: Wingthor Date: Fri, 22 Jan 2021 23:10:22 +0100 Subject: [PATCH] Added a table shuffler using Fisher Yeates algorithm in Utilities/Utils.lua --- Moose Development/Moose/Utilities/Utils.lua | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index 182537ce6..2ca10e6f9 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -1500,4 +1500,24 @@ function UTILS.GetOSTime() end return nil -end \ No newline at end of file +end + +--- Shuffle a table accoring to Fisher Yeates algorithm +--@param #table table to be shuffled +--@return #table +function UTILS.ShuffleTable(t) + if t == nil or type(t) ~= "table" then + BASE:I("Error in ShuffleTable: Missing or wrong tyƄe of Argument") + return + end + math.random() + math.random() + math.random() + local TempTable = {} + for i = 1, #t do + local r = math.random(1,#t) + TempTable[i] = t[r] + table.remove(t,r) + end + return TempTable +end