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

Searching between two numbers?

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

✓ Accepted answer

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 comment

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.

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.

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.

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