generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

How to randomize a table?

Previous Thread :: Next Thread 
Lua_Coder is not online. Lua_Coder
Joined: 25 Feb 2016
Total Posts: 13
27 Feb 2016 06:53 PM
For some reason this only gives me one result.

tablel = {1,2,3,4,5,6,7,8,9}
tablesone = {}
tablestwo = {}


for i = 1,50 do
for i,v in pairs(tablel) do
table.insert(tablesone,tablel[i])
end

repeat
table.remove(tablel,1)
until
tablel[1] == nil


repeat
a = math.random(1,#tablesone)
table.insert(tablestwo,tablesone[a])
table.remove(tablesone,a)
until
tablesone[1] == nil

for i,v in pairs(tablestwo) do
table.insert(tablel,v)
end

repeat
table.remove(tablestwo,1)
until
tablestwo[1] == nil
end

for i,v in pairs(tablel) do
print(tablel[i])
end



Report Abuse
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
27 Feb 2016 07:06 PM
function randTable(table)
for i=1,#table*5 do
local spot1=math.random(1,#table)
local spot2
repeat spot2=math.random(1,#table) wait() until spot2~=spot1
local temp=table[spot1]
table[spot1]=table[spot2]
table[spot2]=temp
wait()
end
end

maybe this?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image