What should I do if I want to randomly pick out five different colors and numbers of playing cards?

I want the program to randomly issue five cards with different colors and numbers (it doesn"t matter if there are occasional cards with the same number), but I find that five cards are always the same.

import random
suites = ["Hearts", "Diamonds", "Spades", "Clubs"]
cardFaces = ["Ace", 2, 3, 4, 6, 7, 8, 9, 10, Jack, Queen, King]
cardFace = random.choice (cardFaces)
suite = random.choice (suites)
pickACard = [str (cardFace) + "of" + str (suite)]

hand = []
for i in range (5):-sharp do the body five times
card = pickACard
hand.append (card)
print (hand)

run result:
[["Queen of Clubs"], [" Queen of Clubs"]]

Process finished with exit code 0

am I missing something?


isn't the reason only random once? Loop 5 times but only randomly once, and the current result is the same


random.choice has randomly listed the results before executing the for, and of course, the for loop is all the same.
you can put random.choice in for.


random.seed (time.time ())

)

plus random number seed

PS. When random numbers were not added to our company's lottery program every year, programmers who wrote the code were called to the stage to code review on the spot.


@ dodopy immediately GET to the wrong point.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bde930-1394d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bde930-1394d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?