Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do u make a random number generator?

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.

1 comment

0

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

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

0

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.

0

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.

1

For clarification, math.random doesn't use C's rand anymore. The wiki is not up to date on this function.

0

math.random is picking a number between 1 and 9999 so it could be 504

0

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

0

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.

0

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.

0

Fixed.

0

jesus this answer sucks

0

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.