I want two numbers (18 and 64).
I'm trying to get a number inbetween them (18-64), and generate it randomly.
Help?
I think you're talking about math.random()
.
Here is an example of how to do this:
1 | num 1 = 18 |
2 | num 2 = 64 |
3 |
4 | randomnumber = math.random(num 1 , num 2 ) --Gets a random number between num1 and num2. |
5 |
6 | print (randomnumber) --Print result |
http://wiki.roblox.com/index.php?title=Random_numbers&redirect=no
You're looking for math.random. You'd use it like this:
1 | local num = math.random( 18 , 64 ) |
2 | 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()
.
1 | math.randomseed(tick()) |
2 | local num = math.random( 18 , 64 ) |
3 | 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.