Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sorting a table fully random?

Asked by
gloveshun 119
4 years ago

I am trying to make a Map system, what works, but it is too boring!

ExampleTable = {"Map1", "Map2", "Map3", "Example"}

1 answer

Log in to vote
1
Answered by 4 years ago

Lua doesn't have shuffle function

Here's a quick and not so bad method to shuffle tables:

function shuffle(tbl)
  for i = #tbl, 2, -1 do
    local j = math.random(i)
    tbl[i], tbl[j] = tbl[j], tbl[i]
  end
  return tbl
end
0
This works thanks! gloveshun 119 — 4y
0
This works thanks! gloveshun 119 — 4y
Ad

Answer this question