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

Searching between two numbers?

Asked by 8 years ago

I want two numbers (18 and 64).

I'm trying to get a number inbetween them (18-64), and generate it randomly.

Help?

3 answers

Log in to vote
2
Answered by 8 years ago

I think you're talking about math.random().

Here is an example of how to do this:

num1 = 18
num2 = 64

randomnumber = math.random(num1, num2) --Gets a random number between num1 and num2.

print(randomnumber) --Print result

http://wiki.roblox.com/index.php?title=Random_numbers&redirect=no

1
As Pyron explained by adding math.randomseed(tick()) the resulting number will be more random as tick() gets the seconds since Epoch 1970. It is best to keep this at the beggining of the script. UniversalDreams 205 — 8y
Ad
Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

You're looking for math.random. You'd use it like this:

local num = math.random(18, 64)
print(num)

This would print a number between 18 and 64. If you want it to be different each time it runs, though, you'll need to use a seed. A commonly used one is tick().

math.randomseed(tick())
local num = math.random(18, 64)
print(num)

This would be more random than the first example. Hope this helped.

Log in to vote
0
Answered by 8 years ago

Well, I asked if you could be in-depth about this. But I will attempt answering it anyway :)

Essentially, all you need to do is create two variables of math.random(). Heehee.

local x = math.random(18,64) local y = math.random(18,64)

These two variables store randomly generated numbers between 18 and 64. You can use the variables X and Y for whatever you need past this point.

Answer this question