Jump to content

During the live stream someone in the chatroom suggested to try a Deck of Cards shuffler so here ...


G+_L I
 Share

Recommended Posts

Shuffling a deck of cards is one of those deceptively simple looking things that is very easy to get wrong. Your method here is in fact exactly mathematically correct, so congrats for getting that right. On the downside, it will be dreadfully slow, not least because you're using strings for internal representation, but also adding and removing from lists is complex.

Link to comment
Share on other sites

Thanks for the feedback. I did some research and found out that the random module actually has a random.shuffle() method. Go figure!

 

So I decided to test both ways to shuffle against my list of strings and a list of  52 integers ( range(52) ).

 

I did see a small speed bump (0.04 seconds from 10000 shuffles) from sorting integers vs strings, but a large jump (0.9 seconds) from using random.shuffle() vs my code.

Link to comment
Share on other sites

 Share

×
×
  • Create New...