title: IndexOutOfBounds Exception for Card Shuffler
body: <p>I am trying to create a card shuffler method and I am currently having trouble with an IndexOutOfBounds exception.  I can't seem to understand why it is erroring out even after working through the code.</p>
  <pre><code>public static ArrayList&lt;Card&gt; shuffle(ArrayList&lt;Card&gt; currDeck) {
          var newDeck = new ArrayList&lt;Card&gt;();
          int length = currDeck.size();
          Random rand = new Random();
          int counter = 0;
  
          while (length != 0) {
              int index = rand.nextInt(length - 1);
              newDeck.set(counter, currDeck.get(index));
              currDeck.remove(currDeck.get(index));
              length --;
              counter ++;
          }
  
  
          return newDeck;
      }
  </code></pre>
  <p>Thanks!</p>