is there any way to generate a random string (text) or number?
✓ ANSWER ACCEPTED
is there any way to generate a random string (text) or number?
2 answers
✓ Accepted answer
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
5 comments
0
That will be too complicated and just for the whole alphabet, you will need 25 elseifs and 1 if statement.
0
But it is possible to make it your way, but much simpler. Instead of doing string = "Option 1", you could do string = "Option "..number
0
Right, forgot about that haha/
0
is there any way not to fall in the same numbers?
0
What do you mean?
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
interesting! is there any way I can activate this script and not fall into the same word?
What do you mean? Which script are you talking about?
of the script you created. I am asking if there is any way to program the script so that this word (ToTxt) is not the same as the one generated previously