aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_util.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-08-06 16:35:49 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-08-06 16:35:49 +0100
commit5fe80e02c8e13ff5d556eb4801087166103ae4a1 (patch)
tree4b3485e66c0fa3f6bd3715838c32194f2a0b8611 /lualib/lua_util.lua
parente2bc6faca69eeef27cf79f134d7517f424ff196d (diff)
downloadrspamd-5fe80e02c8e13ff5d556eb4801087166103ae4a1.tar.gz
rspamd-5fe80e02c8e13ff5d556eb4801087166103ae4a1.zip
[Minor] Add lua_util.shuffle
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r--lualib/lua_util.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 9dc017839..929488929 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -1461,4 +1461,19 @@ exports.maybe_smtp_quote_value = function(str)
return str
end
+---[[[
+-- @function lua_util.shuffle(table)
+-- Performs in-place shuffling of a table
+-- @param {table} tbl table to shuffle
+-- @return {table} same table
+--]]]
+exports.shuffle = function(tbl)
+ local size = #tbl
+ for i = size, 1, -1 do
+ local rand = math.random(size)
+ tbl[i], tbl[rand] = tbl[rand], tbl[i]
+ end
+ return tbl
+end
+
return exports