jeudi 24 octobre 2019

How do I take UNIQUE random choice from two lists

I have two lists that defines a card

values  =  ['A', 'K', 'Q', 'J', '10', '9', '8', '7', '6', '5', '4', '3', '2']
marks   =  ['spade', 'hearts', 'diamond', 'club']

I want to have 12 unique cards, so my output should look like

('9', 'diamond')
('K', 'hearts')
('Q', 'hearts')
('7', 'spade')
('A', 'diamond')
('3', 'diamond')
('Q', 'diamond')
('3', 'hearts')
('7', 'hearts')
('2', 'diamond')
('2', 'hearts')
('5', 'spade')

I have used random choice to get this far, my code is here

count = 0
while count != 12:
    value = random.choice(values)
    mark = random.choice(marks)
    card = Card(value, mark) 
    # I have a class named Card, generate() returns a tuple of mark and value for card
    print(card.generate())
    count += 1

But it does not provide me unique values. Please let me know or through me a resource to learn how to get unique value by random choice from two lists.




Aucun commentaire:

Enregistrer un commentaire