|
| 27 Jan 2012 11:04 PM |
how would i use math.random to choose a radom a random wait time between 1 and 10. I tried this but it did not work wait(math.random(1,10)) |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Jan 2012 11:05 PM |
| Maybe try using variables. |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2012 11:05 PM |
You sure it didn't work? that looks perfectly fine, check the rest of the script you have it in. Also, if you put "math.randomseed(tick())" at the beginning of your script, it makes it truly random. |
|
|
| Report Abuse |
|
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 27 Jan 2012 11:06 PM |
wait(math.random(10)) or wait(math.random(1,10))
Both are correct. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
|
| 27 Jan 2012 11:10 PM |
| @miz, y? it's just longer :P |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Jan 2012 11:13 PM |
@blue
math.random takes 2 arguements. minimum and maximum. To be specific it's good to say 1, 10 |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2012 11:15 PM |
@miz,
math.random can only take 1 argument. If so, it'll pick a number btwn 1 and the argument. |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2012 11:15 PM |
can take** not can only take.
(Floodcheck: 2 Me: 0) |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2012 11:15 PM |
| Technically it'd be better to do math.random(10) since it's less code and will take up less bytes. Of course, those 2 - 3 digits would be like, 5 bytes. So..Not a big difference. |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2012 11:17 PM |
| ok, thanks i figured it out |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Jan 2012 11:18 PM |
| Yeah but think about it. what if you want it to do 5,10 seconds instead of 1,10? |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2012 11:20 PM |
| But here he doesn't, so math.random(10); is perfectly fine. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 27 Jan 2012 11:21 PM |
"Also, if you put "math.randomseed(tick())" at the beginning of your script, it makes it truly random."
For the billionth time, math.random() is already random. ._. It should already use the system time (returned by tick()) as the random's seed. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Jan 2012 11:23 PM |
@swmaniac
It's really not random when it's small numbers. It's only random when it's maximum is high numbers. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 27 Jan 2012 11:24 PM |
| ...Yes, it is random. It's always random. ._. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Jan 2012 11:25 PM |
| It's only random when the maximum number is really high. If the maximum number is like 20 or 10 not really. |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2012 11:27 PM |
| Is it random, however, it's not..Well, as random as we would like it. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 27 Jan 2012 11:29 PM |
math.random range 10
local table = {}
for x = 1, 1000 do local i = math.random(10) table[i] = table[i] and table[i] + 1 or 1 end
print(unpack(table))
Results:
105 110 84 97 87 95 126 105 100 91
Those numbers should average out to 100 each to be the correct probability.
> print((105+110+84+97+87+95+126+105+100+91)/10) 100
It's perfect at 10 range. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Jan 2012 11:29 PM |
@Dark
It is kinda random you have to admit. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 27 Jan 2012 11:30 PM |
At least at range 10 it works out to be the correct probabilities.
Want a further restricted range? |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 27 Jan 2012 11:31 PM |
math.random range 5
local table = {}
for x = 1, 1000 do local i = math.random(5) table[i] = table[i] and table[i] + 1 or 1 end
local a, b, c, d, e = unpack(table)
print(a, b, c, d, e) print((a+b+c+d+e)/5)
180 203 210 208 199 200 |
|
|
| Report Abuse |
|
|