mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(table): added table.shuffle (#718)
This commit is contained in:
@@ -103,10 +103,23 @@ local function table_merge(t1, t2, addDuplicateNumbers)
|
|||||||
return t1
|
return t1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param tbl table
|
||||||
|
---@return table
|
||||||
|
---Shuffles the elements of a table randomly using the Fisher-Yates algorithm.
|
||||||
|
local function shuffle(tbl)
|
||||||
|
local len = #tbl
|
||||||
|
for i = len, 2, -1 do
|
||||||
|
local j = math.random(i)
|
||||||
|
tbl[i], tbl[j] = tbl[j], tbl[i]
|
||||||
|
end
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
table.contains = contains
|
table.contains = contains
|
||||||
table.matches = table_matches
|
table.matches = table_matches
|
||||||
table.deepclone = table_deepclone
|
table.deepclone = table_deepclone
|
||||||
table.merge = table_merge
|
table.merge = table_merge
|
||||||
|
table.shuffle = shuffle
|
||||||
|
|
||||||
local frozenNewIndex = function(self) error(('cannot set values on a frozen table (%s)'):format(self), 2) end
|
local frozenNewIndex = function(self) error(('cannot set values on a frozen table (%s)'):format(self), 2) end
|
||||||
local _rawset = rawset
|
local _rawset = rawset
|
||||||
|
|||||||
Reference in New Issue
Block a user