I have the same problem with unsort table
table.sort(parejas, function(a, b) return math.Rand( 0, 1 ) \> 0.5 end);
I’ve solved with this code. it isn’t elegant, but it works.
--semilla para iniciar el ramdom de botellas
local semilla = math.randomseed
local generarRandom = math.random
--randon siempre genera la misma secuencia numérica si no usamos esta función.
semilla( os.time() + 1 )
local parejas = {"card1", "card2", "card3", "card4", "card5", "card6", "card7", "card8",
"card1", "card2", "card3", "card4", "card5", "card6", "card7", "card8"}
--Unsort function
function desordenarTabla(tempArray)
local i, indiceAletorio
--array unsort
local auxArray = {}
--Total of item
local TotalItem = 16
--unsort array
for i = 1, 16 do
indiceAletorio = generarRandom(TotalItem)
table.insert(auxArray, parejas[indiceAletorio])
table.remove (parejas, indiceAletorio)
TotalItem = TotalItem - 1
end
return auxArray
end
parejas = desordenarTabla(parejas)
[import]uid: 55048 topic_id: 12003 reply_id: 44755[/import]