I wanna know how to make a random number generator between 0 and 9999. Not PRINT text, but on a textlabel. And i want it to have the text Guest before it.
How do u make a random number generator?
5 answers
You could use math.random.
"This function is an interface to the simple pseudo-random generator function rand provided by ANSI C. (No guarantees can be given for its statistical properties.) When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n]."
Example code:
local random = math.random(1,9999) -- random number 1-9999
print(random) -- the random number
6 comments
but I wanna know how to make a random number generator ((BETWEEN))) 0 and 9999. Not PRINT text, but on a textlabel. And i want it to have the text ((Guest)) before it.
Don't number generators in lua repeat after a while? Their is a fix to this I believe, but I'm not going in that deep.
For clarification, math.random doesn't use C's rand anymore. The wiki is not up to date on this function.
math.random is picking a number between 1 and 9999 so it could be 504
or 5405
Heres your answer!
local num = math.random(1,99999) -- put the two numbers you want generated
if num = 1 then
script.Parent.Text = guest
elseif num = 2 then
script.Parent.Text = guest
else
-- All of the other excluded numbers that you most likely will not want in your script.
-- Content here as well
end
5 comments
but I wanna know how to make a random number generator ((BETWEEN))) 0 and 9999. Not PRINT text, but on a textlabel. And i want it to have the text ((Guest)) before it.
You really shouldn't rely on this site for full service to scripting or you can never make anything advanced, but I'll fix it.
Fixed.
jesus this answer sucks
lol
but I wanna know how to make a random number generator ((BETWEEN))) 0 and 9999. Not PRINT text, but on a textlabel. And i want it to have the text ((Guest)) before it.
local Number = math.random(1,9999)
-- Assuming there's a textlabel in workspace called "TextLabel"
workspace.TextLabel.Text = "Guest " .. tostring(Number)
math.random(0,9999)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
This is not a request site, the answers below have taught you what you need. Look up string concatenation for the rest.