title: About once every 24 games the random selection for my Black Jack game fails
body: <p>About 2 months ago I started learning Python. So, I guess this might be obvious to many.</p>
  <p>I made this Black Jack code, and it works more or less as I want it to work. Except from one bug thing which I cannot figure out what happens.</p>
  <p>After getting my initial hand. If, I draw an &quot;Ace of Spades&quot; or an &quot;Ace of Diamonds&quot;, the next card that I will draw will be same (either an &quot;Ace of Spades&quot; or an &quot;Ace of Diamonds&quot; depending on the previous), which is not supposed to happen due that the card should not be anymore in the deck, since it's already in my hand. By the end, there will still be 52 cards, but there will be 5 &quot;Ace&quot;s and a random other will be missing.</p>
  <p>Sorry for the long post. This is my first Stack question and I'm still figure in out how to get the most out of it.</p>
  <p>Here's my long and maybe not so optimal code:</p>
  <pre><code>import random
  
  
  deck = {&quot;Ace of Spades&quot;: 11, &quot;2 of Spades&quot;: 2, &quot;3 of Spades&quot;: 3, &quot;4 of Spades&quot;: 4,
          &quot;5 of Spades&quot;: 5, &quot;6 of Spades&quot;: 6, &quot;7 of Spades&quot;: 7, &quot;8 of Spades&quot;: 8,
          &quot;9 of Spades&quot;: 9, &quot;10 of Spades&quot;: 10, &quot;Jack of Spades&quot;: 10,
          &quot;Queen of Spades&quot;: 10, &quot;King of Spades&quot;: 10,
          &quot;Ace of Hearts&quot;: 11, &quot;2 of Hearts&quot;: 2, &quot;3 of Hearts&quot;: 3, &quot;4 of Hearts&quot;: 4,
          &quot;5 of Hearts&quot;: 5, &quot;6 of Hearts&quot;: 6, &quot;7 of Hearts&quot;: 7, &quot;8 of Hearts&quot;: 8,
          &quot;9 of Hearts&quot;: 9, &quot;10 of Hearts&quot;: 10, &quot;Jack of Hearts&quot;: 10,
          &quot;Queen of Hearts&quot;: 10, &quot;King of Hearts&quot;: 10,
          &quot;Ace of Clovers&quot;: 11, &quot;2 of Clovers&quot;: 2, &quot;3 of Clovers&quot;: 3, &quot;4 of Clovers&quot;: 4,
          &quot;5 of Clovers&quot;: 5, &quot;6 of Clovers&quot;: 6, &quot;7 of Clovers&quot;: 7, &quot;8 of Clovers&quot;: 8,
          &quot;9 of Clovers&quot;: 9, &quot;10 of Clovers&quot;: 10, &quot;Jack of Clovers&quot;: 10,
          &quot;Queen of Clovers&quot;: 10, &quot;King of Clovers&quot;: 10,
          &quot;Ace of Diamonds&quot;: 11, &quot;2 of Diamonds&quot;: 2, &quot;3 of Diamonds&quot;: 3, &quot;4 of Diamonds&quot;: 4,
          &quot;5 of Diamonds&quot;: 5, &quot;6 of Diamonds&quot;: 6, &quot;7 of Diamonds&quot;: 7, &quot;8 of Diamonds&quot;: 8,
          &quot;9 of Diamonds&quot;: 9, &quot;10 of Diamonds&quot;: 10, &quot;Jack of Diamonds&quot;: 10,
          &quot;Queen of Diamonds&quot;: 10, &quot;King of Diamonds&quot;: 10}
  
  ###################################################################################################################
  #####                                   DEFINING DEAL |BJ - SPECIFIC|                                         #####
  
  
  def deal(deck: dict, value: int, cards_in_hand: list, show_list: list):
      &quot;&quot;&quot;
      Deals a card for the Black Jack game and provides the added value of the card.
      :param deck: A Dictionary. Same for everybody.
      :param value: A score. Dependant on the player.
      :param cards_in_hand: A list. Dependant on the player.
      :return: Returns a random selected card, its int value and the updated deck without
      the drawn card
      &quot;&quot;&quot;
      card = random.choice(list(deck))
      cards_in_hand.append(card)
      show_list.append(card)
      hand_value = deck.get(card) + value
      deck.pop(card)
      for card in cards_in_hand:
          if hand_value &gt; 21 and &quot;Ace&quot; in card:
              hand_value = hand_value - 10
              cards_in_hand.remove(card)
      return card, hand_value
  
  ###################################################################################################################
  #####                                                    RESET                                                #####
  
  
  def reset(list1: list, list2: list, list3: list, list4: list,
            int1: int, int2: int, my_choice_: str, bot_choice_: str, deck_: dict):
      &quot;&quot;&quot;
      Resets all the factors of the game to begin from scratch everytime you begin a new game.
      :param list1: Your hand related to value.
      :param list2: Your hand related to figures (or cards).
      :param list3: The bots hand related to value.
      :param list4: The bots related to figures (or cards).
      :param int1: The value or score of your cards.
      :param int2: The value or score of the bots hand.
      :param my_choice_: The decision to 'hit' or 'stand'.
      :param bot_choice_: The bots decision to 'hit' or 'stand'.
      :param deck_: The dictionary containing the full deck of cards.
      :return: Gives you back all the values as originals.
      &quot;&quot;&quot;
      list1 = []
      list2 = []
      list3 = []
      list4 = []
      int1 = 0
      int2 = 0
      bot_choice_ = &quot;&quot;
      my_choice_ = &quot;&quot;
      deck_ = {&quot;Ace of Spades&quot;: 11, &quot;2 of Spades&quot;: 2, &quot;3 of Spades&quot;: 3, &quot;4 of Spades&quot;: 4,
               &quot;5 of Spades&quot;: 5, &quot;6 of Spades&quot;: 6, &quot;7 of Spades&quot;: 7, &quot;8 of Spades&quot;: 8,
               &quot;9 of Spades&quot;: 9, &quot;10 of Spades&quot;: 10, &quot;Jack of Spades&quot;: 10,
               &quot;Queen of Spades&quot;: 10, &quot;King of Spades&quot;: 10,
               &quot;Ace of Hearts&quot;: 11, &quot;2 of Hearts&quot;: 2, &quot;3 of Hearts&quot;: 3, &quot;4 of Hearts&quot;: 4,
               &quot;5 of Hearts&quot;: 5, &quot;6 of Hearts&quot;: 6, &quot;7 of Hearts&quot;: 7, &quot;8 of Hearts&quot;: 8,
               &quot;9 of Hearts&quot;: 9, &quot;10 of Hearts&quot;: 10, &quot;Jack of Hearts&quot;: 10,
               &quot;Queen of Hearts&quot;: 10, &quot;King of Hearts&quot;: 10,
               &quot;Ace of Clovers&quot;: 11, &quot;2 of Clovers&quot;: 2, &quot;3 of Clovers&quot;: 3, &quot;4 of Clovers&quot;: 4,
               &quot;5 of Clovers&quot;: 5, &quot;6 of Clovers&quot;: 6, &quot;7 of Clovers&quot;: 7, &quot;8 of Clovers&quot;: 8,
               &quot;9 of Clovers&quot;: 9, &quot;10 of Clovers&quot;: 10, &quot;Jack of Clovers&quot;: 10,
               &quot;Queen of Clovers&quot;: 10, &quot;King of Clovers&quot;: 10,
               &quot;Ace of Diamonds&quot;: 11, &quot;2 of Diamonds&quot;: 2, &quot;3 of Diamonds&quot;: 3, &quot;4 of Diamonds&quot;: 4,
               &quot;5 of Diamonds&quot;: 5, &quot;6 of Diamonds&quot;: 6, &quot;7 of Diamonds&quot;: 7, &quot;8 of Diamonds&quot;: 8,
               &quot;9 of Diamonds&quot;: 9, &quot;10 of Diamonds&quot;: 10, &quot;Jack of Diamonds&quot;: 10,
               &quot;Queen of Diamonds&quot;: 10, &quot;King of Diamonds&quot;: 10}
      return list1, list2, list3, list4, int1, int2, my_choice_, bot_choice_, deck_
  
  ###################################################################################################################
  #####                                                 BOT PLAYER                                              #####
  
  
  def bot(bot_score: int) -&gt; str:
      &quot;&quot;&quot;
      This bot is made to decide if s/he want to get another card from the dealer or not, depending on
      the value of his hand in relation to 21.
      :param bot_score: An int score of the sum value of cards
      :return: A decision of [Y/N] for 'Yes' or 'No' depending on card values.
      &quot;&quot;&quot;
      if bot_score &lt;= 16:
          bots_choice = &quot;Y&quot;
      else:
          bots_choice = &quot;N&quot;
      return bots_choice
  
  
  ###################################################################################################################
  #####                                                    REFEREE                                              #####
  
  
  def referee(bot_score: int, score: int, show_of_human: list, show_of_robot: list):
      &quot;&quot;&quot;
      Compares the scores of the player and the bot and dictates a winner.
      :param bot_score: The int value of the sum of values of the cards of the bot.
      :param score: The int value of the sum of values of the cards of the player.
      :return: A decision of [Y/N] for 'Yes' or 'No' depending on card values.
      &quot;&quot;&quot;
      referee_says = &quot;&quot;
      if bot_score &gt;= 22 and score &lt;= 21:
          referee_says = &quot;DEALER: Ruben went over 21. You win!&quot;
      elif score &gt;= 22 and bot_score &lt;= 21:
          referee_says = &quot;DEALER: You went over 21. Ruben win!&quot;
      elif bot_score and score &gt;= 22:
          referee_says = &quot;DEALER: You both went over 21. Nobody wins!&quot;
      else:
          if bot_score == score:
              referee_says = &quot;DEALER: It's a tie!&quot;
          elif bot_score &lt; score:
              referee_says = &quot;DEALER: You win!&quot;
          else:
              referee_says = &quot;DEALER: Ruben win!&quot;
      return &quot;YOUR HAND: {1}\nRUBEN'S HAND: {0}\n\nWith a score of:\nYOU: {3}\nRUBEN: {2}\n&quot; \
          .format(show_of_robot, show_of_human, bot_score, score) + referee_says
  
  
  ###################################################################################################################
  #####                                             SCORES &amp; HAND                                               #####
  
  
  score = 0
  bot_score = 0
  my_cards = []
  bots_cards = []
  show_of_hand = []
  show_of_bot = []
  another_bot_card = &quot;&quot;
  another_card = &quot;&quot;
  hit = &quot;Y&quot;
  stand = &quot;N&quot;
  continue_playing = True
  
  
  
  ###################################################################################################################
  #####                                              INTRO &amp; GAME                                               #####
  
  
  input(&quot;Press ENTER to play some Black Jack&quot;)
  print()
  ready_payer_one = input(&quot;DEALER: 'Are you ready to begin?'[Y/N]: &quot;)
  print(&quot;-&quot; * 72)
  
  while continue_playing:
      while ready_payer_one.upper() != &quot;Y&quot; or &quot;N&quot;:
          if ready_payer_one.upper() == &quot;Y&quot;:
              hand, score = deal(deck, score, my_cards, show_of_hand)
              hand2, score = deal(deck, score, my_cards, show_of_hand)
              bot_hand, bot_score = deal(deck, bot_score, bots_cards, show_of_bot)
              bot_hand2, bot_score = deal(deck, bot_score, bots_cards, show_of_bot)
              print(&quot;You got dealt a {} and a {}\n&amp;&quot;.format(hand, hand2))
              print(&quot;Ruben, the robot, got dealt a {} and a face-down card&quot;.format(bot_hand))
              print(&quot;-&quot; * 72)
              while another_bot_card.upper() != stand or another_card.upper() != stand:
                  another_card = input(&quot;DEALER: Would you like another card?[Y/N]: &quot;)
                  another_bot_card = bot(bot_score)
                  print(&quot;-&quot; * 72)
                  if another_card.upper() != hit or stand:
                      if another_card.upper() == hit:
                          hand, score = deal(deck, score, my_cards, show_of_hand)
                          print(&quot;You draw a {},&quot;.format(hand))
                      elif another_card.upper() == stand:
                          print(&quot;You stand,&quot;)
                      elif another_card.upper() != hit or stand:
                          another_card = input(&quot;DEALER: Dude, that's not a valid option. 'Y' to Hit or 'N' to Stand: &quot;)
                          print(&quot;-&quot; * 72)
                          if another_card.upper() == hit:
                              hand, score = deal(deck, score, my_cards, show_of_hand)
                              print(&quot;You draw a {}&quot;.format(hand))
                          elif another_card.upper() == stand:
                              print(&quot;You stand&quot;)
  
                  if another_bot_card.upper() != stand:
                      bot_hand, bot_score = deal(deck, bot_score, bots_cards, show_of_bot)
                      print(&quot;Ruben draw a {}\n&quot;.format(bot_hand) + &quot;-&quot; * 72)
                  else:
                      print(&quot;Ruben stands\n&quot; + &quot;-&quot; * 72)
  
              final = referee(bot_score, score, show_of_hand, show_of_bot)
              print(final + &quot;\n&quot; + (&quot;-&quot; * 72))
              my_cards, bots_cards, show_of_hand, show_of_bot, score, bot_score, another_card, another_bot_card, deck = \
                  reset(my_cards, bots_cards, show_of_hand, show_of_bot, score, bot_score, another_card, another_bot_card,
                        deck)
              break
  
          elif ready_payer_one.upper() == &quot;N&quot;:
              print(&quot;DEALER: Thanks for the interest. Later!&quot;)
              break
          else:
              ready_payer_one = input(&quot;DEALER: That's not a valid choice. Please, choose 'Y' for Play or 'N' to Quit. &quot;)
              print(&quot;-&quot; * 72)
      again = input(&quot;DEALER: Type 'Iztaccihuatl' to PLAY AGAIN or 'N' to quit: &quot;)
      print(&quot;DEALER: Haha trolled you. For next time, you can type anything to PLAY AGAIN...&quot;)
      print(&quot;-&quot; * 72)
      if again.upper() == &quot;N&quot;:
          print(&quot;MAURICIO: Thanks for playing!&quot;)
          continue_playing = False
  </code></pre>