Table Shuffle - Finally! Shuffle a table in Lua!

If you’re like me, you realized that Lua doesn’t have a native way to shuffle a table >:(.
Simple script for a simple problem.

Installation

  • Find Shuffle Table in the community packages
  • Add shuffleScript to whichever script needs it (i.e. gameController)

Usage
In your gameController script, or where ever your script is, define the following local variable:

local shuffle = {}

In your init script, add the following:

function GameControllerScript:Init()
  shuffle = self:GetEntity().shuffleScript
end

Usage

print("Shuffling:")
local newTable = shuffle:shuffle({"a","b","c","d"}) do
for _, value in pairs(newTable)
  print(value)
end

3 Likes

It’s very useful, it has been a great help to me.
Good job!