|
| 31 Jan 2016 08:59 AM |
For example: math.randomseed(math.floor(os.time())) T = {4,2,3,4,5,6,7,4,8,5,2,4,2,7,3,7}
How would I use math.random and get a value off that table?
This siggy is copyrighted ©
|
|
|
| Report Abuse |
|
|
|
| 31 Jan 2016 09:01 AM |
print(t[math.random(1, #t)])
Will error if t is empty. |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 31 Jan 2016 10:18 AM |
@128Gigabytes Should be: print(t[math.random(1, #T)])
His variable is T, not t. |
|
|
| Report Abuse |
|
|
XYuy
|
  |
| Joined: 24 Dec 2010 |
| Total Posts: 5628 |
|
|
| 31 Jan 2016 10:27 AM |
@Aeth
That doesn't matter.
He gave the right example, and anyone who knows how to script knows how to replace variables.
|
|
|
| Report Abuse |
|
|
Gensoki
|
  |
| Joined: 15 Feb 2014 |
| Total Posts: 1982 |
|
|
| 31 Jan 2016 10:30 AM |
Yet it should be print(T[math.random(1, #T)]) not t :)
http://www.roblox.com/Schwarzesmarken-Opening-TV-Size-item?id=345656154 #code "Let's just say goodbye" |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 31 Jan 2016 10:34 AM |
| @XYuy It does matter. The level of op is not known and code provided should work for the given example. It was expressed as code that works and should do so. |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 31 Jan 2016 10:35 AM |
| I also made a mistake, though, as Gensoki pointed out. I only changed the second t: print(T[math.random(1, #T)]) |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2016 02:29 PM |
While we are at it this will stop it from erroring if the table is empty
print(T[(#T > 0) and math.random(1, #T) or 0]) |
|
|
| Report Abuse |
|
|