is there any way to generate a random string (text) or number?
Hi Iytew!
To make a random string:
1 | function doText(numLetters) |
2 | local totTxt = "" |
3 | for i = 1 ,numLetters do |
4 | totTxt = totTxt..string.char(math.random( 97 , 122 )) |
5 | end |
6 | print (totTxt) |
7 | end |
8 |
9 | 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:
1 | local avaliablestrings = { "Hello!" , "Goodbye." , "How are you?" } |
2 | print (avaliablestrings [ math.random( 1 , #avaliablestrings) ] |
To make a random number:
1 | local chosenNumber = math.random( 1 , 20 ) --Generates a number between 1 and 20. Change it to whatever you want. |
2 |
3 | print (chosenNumber) |
Hope I helped, LennyPlayzYT.
Yes, there is a way.
You would have to use math.random for that.
1 | math.random(min, max) -- Generates an integer between your minimum and maximum value. |
2 | math.random(max) -- Generates an integer between 1 and your specified maximum value. |
3 | math.random() -- Generates a number between 0 and 1. It's going to be a decimal. |
Here's how you would use it:
01 | local string -- Blank variable, no value. |
02 | local number = math.random( 3 ) -- Chooses a random number between 1 and 3 |
03 |
04 | -- This is how you would generate a string with the math.random function. |
05 | if number = = 1 then -- The two equal signs are what you use to compare two values. |
06 | string = "Option 1" -- The one equal sign is what you use to set a variable to a specific value. |
07 | elseif number = = 2 then |
08 | string = "Option 2" |
09 | elseif number = = 3 then |
10 | string = "Option 3" |
11 | end |