Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make a math.random generator BUT with words?

Asked by 4 years ago
Edited 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

For example, instead of having lets say 1,5 it would be: hello,(or) goodbye

Okay so im trying to make this script print out words just like math.random prints out numbers, I know how to do math rand b ut not with words

Here is my math.random

01while true do
02 
03 
04    wait(0.8)
05 
06local variable1 =  math.random(1,4)
07local variable2 = math.random(5,10)
08 
09 
10    print(variable1, variable2)
11 
12 
13end

Any help appreciated

1 answer

Log in to vote
1
Answered by
Roger111 347 Moderation Voter
4 years ago
Edited 4 years ago

ANSWER: You will still need a random number, and you will use that random number to get a random index from an Array of words.

Example:

01local wordList = {
02    "Hello",
03    "Goodbye",
04    "Yes",
05    "No",
06    "What is going on here?"
07}
08 
09function randomWord()
10    return wordList[math.random(#wordList)]
11end
12 
13print(randomWord())
14print(randomWord())
15print(randomWord())
0
You mean math.random(1,#wordlist) . You forgot the start number. PrismaticFruits 842 — 4y
0
Nope! You don't need to put the start number. Roger111 347 — 4y
1
When you call math.random() with one parameter, it will immediately get a number within that range. Nickuhhhhhhhhhhhhhhh 834 — 4y
0
??? if you call math.random() with 1 arg, then it will return a number in the range of [1,arg] see https://developer.roblox.com/en-us/api-reference/lua-docs/math VerdommeMan 1479 — 4y
Ad

Answer this question