52 Deck Card Shuffling/Randomizer (no repeats)

The problem with this is that it prints duplicates.

Did you solve it yet?

Sort of, I am trying different things for yours and also @Limited_Unique’s code. I am not very good with tables so with yours, I am having difficulty receiving table.insert values for the randomizer, and with Limited’s, I am having trouble solving the duplicated problem.

I truly appreciate your help.

1 Like
local suits = {"Clubs", "Diamonds", "Hearts", "Spades"}
local faces = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}

local function randCard()
	return math.random(1, 52)
end

local function giveHand()
	local cards = {}
	local hand = {}
	for _, suit in pairs(suits) do
		for _, face in pairs(faces) do
			local card = face.." of "..suit
			table.insert(cards, card)
		end
	end
	
	for i = 1, 5 do
		local randNum = randCard()
		local card = cards[randNum]
		for index, aCard in pairs(cards) do
			if card == aCard then
				table.remove(cards, index)
			end
		end
		table.insert(hand, card)
	end
	
	for _, card in pairs(hand) do
		print(card)
	end
end

giveHand()
1 Like