title: Shuffling deck algorithm in Java
body: <p>Hey guys I was just reading my notes and had a difficult time understanding the algorithm they used to shuffle cards. Here's what it looks like. Can someone please explain each line in as much detail as they can? Thank you very much.</p>
  
  <pre><code>public void shuffle()
  {
      // next call to method dealCard should start at deck[0] again
      currentCard = 0;
  
      // for each Card, pick another random card (0-51) and swap them
      for (int first = 0; first &lt; deck.length; first++)
      {
          // select a random number between 0 and 51
          int second = randomNumbers.nextInt(NUMBER_OF_CARDS);
  
          // swap current Card with randomly selected Card
          Card temp = deck[first];
          deck[first] = deck[second];
          deck[second] = temp;
      }
  }
  </code></pre>