SLY3
|
  |
| Joined: 10 Jul 2008 |
| Total Posts: 1700 |
|
|
| 27 Jan 2015 09:23 AM |
Simple question that I'm surprised I don't actually know the answer to, how do you do math.random() between two numbers that aren't whole numbers?
If you do math.random(0.2,0.8) it returns 0. |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 27 Jan 2015 09:29 AM |
math.random(2, 8) / 10
print(math.random(2, 8) / 10) -->0.2 to 0.8 |
|
|
| Report Abuse |
|
|
SLY3
|
  |
| Joined: 10 Jul 2008 |
| Total Posts: 1700 |
|
|
| 27 Jan 2015 09:30 AM |
| That's actually a really good idea, thanks. |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 27 Jan 2015 09:32 AM |
it would be cool if math.random had a third argument where it was like
math.random(0.2, 0.8, 0.1)
so its like
between 0.2 and 0.8, and it'll be a tenth of a number
or like
math.random(10, 100, 10)
would be either 10 20 30 40 50 60 70 80 90 or 100 |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2015 09:35 AM |
| Do it like Java where you manipulate a call to math.random() with no arguments and like multiply it. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 27 Jan 2015 09:52 AM |
Pretty much every language has support for both, and it's really not worth the effort it would take.
(math.random() * (0.8 - 0.2)) + 0.2 |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 27 Jan 2015 09:59 AM |
do local omath = math; math = setmetatable({}, {__index = math}); function math.random(...) if #{...} >= 3 then return omath.random(...)*{...}[3]; else return omath.random(...) end end end local math = math; |
|
|
| Report Abuse |
|
|