|
| 30 Mar 2014 02:11 AM |
How can I do this: mytable = {1,2,3,4,5} and then mix it around so it can POSSIBLY go into a random order like this: mytable = {3,1,5,4,2} |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 30 Mar 2014 02:15 AM |
local tab = {} --Insert ST00f local newtable = {} math.randomseed(tick()) while #tab > 0 do index = math.random(1, #tab) newtable[#newtable+1] = tab[index] table.remove(tab, index) end tab = newtable |
|
|
| Report Abuse |
|
|
iYoshiFox
|
  |
| Joined: 14 Apr 2012 |
| Total Posts: 1058 |
|
|
| 30 Mar 2014 02:16 AM |
local Table = {1, 2, 3, 4, 5}
function Mix(tbl) --tbl = the table ur mixing local mixed = {} local g = tbl repeat wait() local rand = math.random(1, #g) table.insert(mixed, g[rand]) table.remove(g, g[rand]) until #mixed == #tbl end |
|
|
| Report Abuse |
|
|
iYoshiFox
|
  |
| Joined: 14 Apr 2012 |
| Total Posts: 1058 |
|
|
| 30 Mar 2014 02:17 AM |
MrChubbs, yours would look like this;
newtable = { [1] = 1 [2] = 2 -Ect } |
|
|
| Report Abuse |
|
|
iYoshiFox
|
  |
| Joined: 14 Apr 2012 |
| Total Posts: 1058 |
|
|
| 30 Mar 2014 02:19 AM |
Put this at the end of mu function under
'until #mixed == #tbl' return mixed
then, if you did this
for _, v in pairs(Mix(Table)) do --You already have the contents. end |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 30 Mar 2014 02:21 AM |
| Mine randomizes tables correctly, I just checked it. |
|
|
| Report Abuse |
|
|
|
| 30 Mar 2014 02:33 AM |
local Table = {1, 2, 3, 4, 5} print(Table[3]) function Mix(tbl) --tbl = the table ur mixing mixed = {} local g = tbl repeat wait() local rand = math.random(1, #g) table.insert(mixed, g[rand]) table.remove(g, g[rand]) until #mixed == #tbl return mixed end print(mixed[3])
--With this i am getting error of mixed is a nil value? |
|
|
| Report Abuse |
|
|
iYoshiFox
|
  |
| Joined: 14 Apr 2012 |
| Total Posts: 1058 |
|
|
| 30 Mar 2014 02:34 AM |
Do this:
print(Mix(Table)[3]) |
|
|
| Report Abuse |
|
|
|
| 30 Mar 2014 02:35 AM |
| Oh right, forgot it was a function, will test. |
|
|
| Report Abuse |
|
|
iYoshiFox
|
  |
| Joined: 14 Apr 2012 |
| Total Posts: 1058 |
|
|
| 30 Mar 2014 02:36 AM |
| Tell me if it worked.. I did do it off the top of my head.. |
|
|
| Report Abuse |
|
|
|
| 30 Mar 2014 02:37 AM |
Hmm, still getting errors. I'm going to go with MrChubbs script
Thanks for the help anyways! |
|
|
| Report Abuse |
|
|