is there any way to generate a random string (text) or number?
Hi Iytew!
To make a random string:
function doText(numLetters) local totTxt = "" for i = 1,numLetters do totTxt = totTxt..string.char(math.random(97,122)) end print(totTxt) end doText(5) --Amount of letters in the string
*Legojoker created that script
Or if you want to choose a random string from a list of strings:
local avaliablestrings = {"Hello!", "Goodbye.", "How are you?"} print(avaliablestrings[math.random(1, #avaliablestrings)]
To make a random number:
local chosenNumber = math.random(1, 20) --Generates a number between 1 and 20. Change it to whatever you want. print(chosenNumber)
Hope I helped, LennyPlayzYT.
Yes, there is a way.
You would have to use math.random for that.
math.random(min, max) -- Generates an integer between your minimum and maximum value. math.random(max) -- Generates an integer between 1 and your specified maximum value. math.random() -- Generates a number between 0 and 1. It's going to be a decimal.
Here's how you would use it:
local string -- Blank variable, no value. local number = math.random(3) -- Chooses a random number between 1 and 3 -- This is how you would generate a string with the math.random function. if number == 1 then -- The two equal signs are what you use to compare two values. string = "Option 1" -- The one equal sign is what you use to set a variable to a specific value. elseif number == 2 then string = "Option 2" elseif number == 3 then string = "Option 3" end