mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 07:34:35 +00:00
[added] tablex.take_random
which is like pick_random
but removes the element
This commit is contained in:
parent
24bcc78616
commit
16c183ec31
@ -134,6 +134,14 @@ function tablex.pick_random(t, r)
|
|||||||
return t[_random(1, #t, r)]
|
return t[_random(1, #t, r)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--take a random value from a table (or nil if it's empty)
|
||||||
|
function tablex.take_random(t, r)
|
||||||
|
if #t == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return table.remove(t, _random(1, #t, r))
|
||||||
|
end
|
||||||
|
|
||||||
--shuffle the order of a table
|
--shuffle the order of a table
|
||||||
function tablex.shuffle(t, r)
|
function tablex.shuffle(t, r)
|
||||||
for i = 1, #t do
|
for i = 1, #t do
|
||||||
|
Loading…
Reference in New Issue
Block a user