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

How do u make a random number generator? [closed]

Asked by 4 years ago
Edited 4 years ago

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
This is not a request site, the answers below have taught you what you need. Look up string concatenation for the rest. Ziffixture 6913 — 4y

Closed as Not Constructive by raid6n, botw_legend, and EzraNehemiah_TF2

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

5 answers

Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited by Ziffixture 4 years ago

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
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. theepicjairi -2 — 4y
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. ifreakinlostmyacount 52 — 4y
1
For clarification, math.random doesn't use C's `rand` anymore. The wiki is not up to date on this function. NewVoids 97 — 4y
View all comments (2 more)
0
math.random is picking a number between 1 and 9999 so it could be 504 iWasThisi -15 — 4y
0
or 5405 iWasThisi -15 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
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. theepicjairi -2 — 4y
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. ifreakinlostmyacount 52 — 4y
0
Fixed. ifreakinlostmyacount 52 — 4y
0
jesus this answer sucks greatneil80 2647 — 4y
0
lol sean_thecoolman 189 — 4y
Log in to vote
0
Answered by 4 years ago

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.

Log in to vote
0
Answered by
Pupppy44 671 Moderation Voter
4 years ago
local Number = math.random(1,9999)
-- Assuming there's a textlabel in workspace called "TextLabel"
workspace.TextLabel.Text = "Guest " .. tostring(Number)
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
math.random(0,9999)