How To Choose A Random Item From A Table Lua

[Solved] How To Choose A Random Item From A Table Lua | Lua - Code Explorer | yomemimo.com
Question : how to choose a random item from a table lua

Answered by : adxm

local myTable = {"Hello", "World", "Lua"}
print(myTable[1]) --Outputs: "Hello"
print(#myTable) --Outputs: 3 because we have 3 values in our table
print(myTable[math.random(1, #myTable)]) --Outputs a random value in our table!

Source : | Last Update : Tue, 05 Jan 21

Question : how to get a random number in lua

Answered by : adxm

local randomNumber1 = math.random(1, 10) --Returns a number between 1 and 10.
local randomNumber2 = math.random(10) --Also returns a number between 1 and 10.
print(randomNumber1, randomNumber2) --OUTPUT EXAMPLE: "6, 8"

Source : | Last Update : Tue, 05 Jan 21

Answers related to how to choose a random item from a table lua

Code Explorer Popular Question For Lua