G+_L I Posted May 16, 2014 Share Posted May 16, 2014 During the live stream someone in the chatroom suggested to try a Deck of Cards shuffler so here is one. Also tried to create a Mastermind game: http://pastebin.com/6rW9eNNw http://pastebin.com/Q7EJweYb Link to comment Share on other sites More sharing options...
G+_Lee Crocker Posted May 16, 2014 Share Posted May 16, 2014 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 More sharing options...
G+_L I Posted May 17, 2014 Author Share Posted May 17, 2014 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 More sharing options...
G+_L I Posted May 17, 2014 Author Share Posted May 17, 2014 Update: http://pastebin.com/kngT60ht Link to comment Share on other sites More sharing options...
G+_Shannon Morse Posted May 22, 2014 Share Posted May 22, 2014 The updated one works like a charm. :) Gonna show it off on the episode tomorrow. Link to comment Share on other sites More sharing options...
G+_Lee Crocker Posted May 22, 2014 Share Posted May 22, 2014 Just for comparison, my ojcardlib library can fully simulate a billion hands of blackjack in about a minute. Could't do that in Python. (Although you can call my C code from Python and still do pretty well.) Link to comment Share on other sites More sharing options...
Recommended Posts