Need a script that can pick from a specific set of numbers at random

Hello.
I am trying to figure out how to get a script to pick from a specific number set.
script.Parent.Text = "3022" or "3122" or "3222" or "3322" or "3422"
I’m trying to pick at one from the five numbers that are shown here but the script always defaults to 3022.

Not that familier with the whole list and tables of lua, but the big idea would be to use some sort of list (i call it that im not sure what its called in lua), put all the numbers in it, and then use a math.random statement to grab the item at a random location of the “list”

ah yes its called an array like in java

You need to create an array with all the possible numbers (as strings) that you want. Then we can use the Random Object to generate a random number — That will be used to pick a number from our previous array. (We’re basically gonna index it)

It’s really recommended to create a function that automatically does that instead of always needing to paste the same code over-and-over again. Mainly if you’re gonna need to pick numbers several times.

By the way, Ensure that you add atleast 2 or more numbers, As not adding enough may result in errors and will always return the same number.

About the error part, This mainly happens with math.random but i’m not sure if it also goes for the Random Object.

And if you may ask, The reason of why we’re using Random instead of math.random is because Random provides a better pseudo-number generation rather then math random.

local PossibleNumbers = {"3022", "3122", "3222", "3322", "3422"}
local RNG = Random.new()

local function GetRandomNumber()
    local TotalNumbers = table.getn(PossibleNumbers)
    local RandomIndex = RNG:NextInteger(1, TotalNumbers)
    local ChosenNumber = PossibleNumbers[RandomIndex]
    return ChosenNumber
end

script.Parent.Text = GetRandomNumber()