Shuffle Table Items

 

Hi everybody , how i can Shuffle  table  D  ?    
 
D={  A={flag=false,rank=1,png=“D1”}  ,    B={flag=true,rank=1,png=“HA”}  }

Use something along these lines.

local function Shuffle(iTable) local n, order, oTable = #iTable, {}, {} for i=1,n do order[i] = { rnd = math.random(), idx = i } end table.sort(order, function(a,b) return a.rnd \< b.rnd end) for i=1,n do oTable[i] = iTable[order[i].idx] end return oTable end

Then just say d = Shuffle(d)

Use something along these lines.

local function Shuffle(iTable) local n, order, oTable = #iTable, {}, {} for i=1,n do order[i] = { rnd = math.random(), idx = i } end table.sort(order, function(a,b) return a.rnd \< b.rnd end) for i=1,n do oTable[i] = iTable[order[i].idx] end return oTable end

Then just say d = Shuffle(d)