Hi there,
So i'm attempting to "shuffle" a deck of cards, which is just a table with strings of the name of each card.
This way so I can deal the card in order.
For some reason, I always seem to get a pattern when trying to mix the table
Is there a reliable way to mix a table?
My script:
DeckInOrder = {"card1", "card2", "card3"} --// Obviously includes full deck
function ShuffleCards()
local GetCards = {}
for _,v in pairs (DeckInOrder) do
table.insert(GetCards, v)
end
ShuffledDeck = {}
print'Shuffling deck... '
wait()
for i = 1, #GetCards do
local RandomNum = nil
local RandomCard = nil
repeat
RandomNum = math.random(1,#GetCards)
RandomCard = GetCards[RandomNum]
until RandomCard ~= nil
table.insert(ShuffledDeck,RandomCard)
table.remove(GetCards, RandomNum)
wait()
end
print'Finished shuffling!'
return ShuffledDeck
end |