ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
|
| 15 Sep 2012 11:56 AM |
How would you get a script to generate a random number between 2 chosen numbers?
Is it possible? I think I've seen it before.
-[ http://www.roblox.com/Build-Brag-V-2-1-place?id=64950819 ]- |
|
|
| Report Abuse |
|
|
ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
|
| 15 Sep 2012 11:57 AM |
I sound like a newby.
-[ http://www.roblox.com/Build-Brag-V-2-1-place?id=64950819 ]- |
|
|
| Report Abuse |
|
|
|
| 15 Sep 2012 12:50 PM |
print(math.random(2))
> 1
Would be from 1 to 2.
local RandomNumber=math.random(5, 7) print(RandomNumber)
> 5
This would be 5 to 7.
function RandomizeNumbers(Int1, Int2) pcall(function() print(math.random(Int1, Int2)) end) end
RandomizeNumbers(1, 2)
> 2
Make sure the lower number is first, if you're using two arguments.
math.random()
With no arguments, it would be from 0 to 1.
For more information:
http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions#math.random
† KMXD †
|
|
|
| Report Abuse |
|
|
|
| 15 Sep 2012 01:58 PM |
If you want between two numbers WITH decimal places (ie, NOT INTEGERS), you can do this:
function ranWithDec(a, b) if a < b then return math.random()*(b-a)+a else return math.random()*(a-b)+b end end
Though I'm not sure why you'd want decimal places. Who knows. |
|
|
| Report Abuse |
|
|
|
| 15 Sep 2012 02:26 PM |
for i = 1, 120 do print(math.random(8, 30)) end
will print 120 numbers between 8-30. |
|
|
| Report Abuse |
|
|