Why Aren't My Cards Random?
<p>I created this program in my quest to learn Java but every time I run it I get the same cards over and over again. I can't really find the problem, so why aren't my cards random? I don't really get what I'm missing, is my shuffle method incorrect?</p>

<pre><code>package blackjack;

import java.util.Scanner;

public class BlackJack {

 public static void main(String[] args) {

      System.out.println("Are you ready to play BlackJack?");
      System.out.println();


      playBlackjack();
      System.out.println("Thanks for playing!");


   } 


   static boolean playBlackjack() {

      Deck deck;                  
      Hand dealerHand;   
      Hand playerHand;    

      deck = new Deck();
      dealerHand = new Hand();
      playerHand = new Hand();


      dealerHand.addCard( deck.dealCard() );
      playerHand.addCard( deck.dealCard() ); 
      dealerHand.addCard( deck.dealCard() );
      playerHand.addCard( deck.dealCard() );


      System.out.println();


      if (dealerHand.getBlackjackValue() == 21) {
           System.out.println("The dealer have the " + dealerHand.getCard(0)
                                   + " and the " + dealerHand.getCard(1) + ".");
           System.out.println("You have the " + playerHand.getCard(0)
                                     + " and the " + playerHand.getCard(1) + ".");
           System.out.println();
           System.out.println("The dealer has Blackjack! The dealer wins!");
           return false;
      }

      if (playerHand.getBlackjackValue() == 21) {
           System.out.println("Dealer has the " + dealerHand.getCard(0)
                                   + " and the " + dealerHand.getCard(1) + ".");
           System.out.println("User has the " + playerHand.getCard(0)
                                     + " and the " + playerHand.getCard(1) + ".");
           System.out.println();
           System.out.println("You have Blackjack.  You win.");
           return true;
      }
      while (true) {

           // User decides whether to hit or stand

           System.out.println();
           System.out.println();
           System.out.println("Your cards are:");
           for ( int i = 0; i &lt; playerHand.getCardCount(); i++ )
              System.out.println("    " + playerHand.getCard(i));
           System.out.println("The total of your hand is " +     playerHand.getBlackjackValue());
           System.out.println();
           System.out.println("The dealer is showing the " + dealerHand.getCard(0));
           System.out.println();
           System.out.println("Do you hit(type 0) or stand(type 1)? ");
           Scanner input = new Scanner(System.in);
           int choice = input.nextInt();
              if (choice != 0 &amp;&amp; choice != 1){
                 System.out.println("0 or 1 must be inputted to continue ");}
            while (choice != 0 &amp;&amp; choice != 1);

           if ( choice == 1 ) {
               break;
           }
           else {
               Card newCard = deck.dealCard();
               playerHand.addCard(newCard);
               System.out.println();
               System.out.println("You hits and your card is the " + newCard);
               System.out.println("The total of the hand is now " + playerHand.getBlackjackValue());
               if (playerHand.getBlackjackValue() &gt; 21) {
                   System.out.println();
                   System.out.println("Fool of a Took! You went over 21 and busted!");
                   return false;  
               }
           }

      }
      //User has stood at this point. Poor fool


      System.out.println();
      System.out.println("You stand. Wouldn't it be nice to sit sometime?");
      System.out.println("The dealer's cards are "+ dealerHand.getCard(0) + " and the " + dealerHand.getCard(1));
      while (dealerHand.getBlackjackValue() &lt;= 16) {
         Card newCard = deck.dealCard();
         System.out.println("The dealer hits and gets the " + newCard);
         dealerHand.addCard(newCard);
         if (dealerHand.getBlackjackValue() &gt; 21) {
            System.out.println();
            System.out.println("The dealer busted! You win!");
            return true;
         }
      }
      System.out.println("The dealer's total is " + dealerHand.getBlackjackValue());
      System.out.println();
      if (playerHand.getBlackjackValue() == dealerHand.getBlackjackValue()) {
         System.out.println("The house always wins on a tie. You lose :(");
         return false;
      }
      else if (dealerHand.getBlackjackValue() &gt;= playerHand.getBlackjackValue()) {
         System.out.println("The dealer wins as he has " + dealerHand.getBlackjackValue() 
                          + " points to your " + playerHand.getBlackjackValue() + "!");
         return false;
      }
      else {
         System.out.println("You win because you had " + playerHand.getBlackjackValue() 
                          + " points while the dealer only had " + dealerHand.getBlackjackValue() + "!");
         return true;
      }

   }
}



package blackjack;

public class Card {

private int suit;
private int rank;
public final static int SPADES = 0,       // Codes for the 4 suits.
                        HEARTS = 1,
                        DIAMONDS = 2,
                        CLUBS = 3;

public final static int ACE = 1,          
                  JACK = 11,            
                  QUEEN = 12,
                  KING = 13;



public Card(int cRank, int cSuit) {
    rank = cRank;
    suit = cSuit;
}

public int getSuit() {
    return suit;
}

public int getRank() {
    return rank;
}

public String getSuitString() {
        // Return a String representing the card's suit.
        // (If the card's suit is invalid, "??" is returned.)
    switch ( suit ) {
       case SPADES:   return "Spades";
       case HEARTS:   return "Hearts";
       case DIAMONDS: return "Diamonds";
       case CLUBS:    return "Clubs";
       default: return "I don't even know";

    }
}

public String getRankString() {
    switch ( rank ) {
       case 1:   return "Ace";
       case 2:   return "2";
       case 3:   return "3";
       case 4:   return "4";
       case 5:   return "5";
       case 6:   return "6";
       case 7:   return "7";
       case 8:   return "8";
       case 9:   return "9";
       case 10:  return "10";
       case 11:  return "Jack";
       case 12:  return "Queen";
       case 13:  return "King";
       default: return "This is impossible!";
    }


}

@Override
public String toString() {
    return getRankString() + " of " + getSuitString();
}


}



package blackjack;

public class Deck {
private Card[] deck;   
private int cardsUsed; 

public Deck() {
   deck = new Card[52];
   int l = 0;
   for ( int suit = 0; suit &lt;= 3; suit++ ) {
      for ( int value = 1; value &lt;= 13; value++ ) {
         deck[l] = new Card(value,suit);
         l++;
      }
   }
   cardsUsed = 0;
}

public void shuffle() {
    for ( int i = 51; i &gt; 0; i-- ) {
        int rand = (int)(Math.random()*(i+1));
        Card temp = deck[i];
        deck[i] = deck[rand];
        deck[rand] = temp;
    }
    cardsUsed = 0;
}

public int cardsLeft() {
    return 52 - cardsUsed;
}

public Card dealCard() {
    if (cardsUsed == 52){
       shuffle();}
    cardsUsed++;
    return deck[cardsUsed - 1];

}
}



package blackjack;

import java.util.*;

public class Hand {

private ArrayList hand; 

public Hand() {
   hand = new ArrayList();
}

public void clear() {
  hand.clear();
}

public void addCard(Card c) {
  if (c != null){
     hand.add(c);
  }
}

public void removeCard(Card c) {
  hand.remove(c);
}

public void removeCard(int location) {
  if (location &gt;= 0 &amp;&amp; location &lt; hand.size()){
     hand.remove(location);
  }
   }

public int getCardCount() {
  return hand.size();
}

public Card getCard(int location) {
  if (location &gt;= 0 &amp;&amp; location &lt; hand.size()){
     return (Card)hand.get(location);}
  else{
     return null;
  }
 } 
public void sortBySuit() {
  ArrayList newHand = new ArrayList();
  while (hand.size() &gt; 0) {
     int pos = 0; 
     Card c = (Card)hand.get(0); 
     for (int i = 1; i &lt; hand.size(); i++) {
        Card c1 = (Card)hand.get(i);
        if ( c1.getSuit() &lt; c.getSuit() ||
                (c1.getSuit() == c.getSuit() &amp;&amp; c1.getRank() &lt; c.getRank()) ) {
            pos = i;
            c = c1;
        }
     }
       Object remove = hand.remove(pos);
     newHand.add(c);
  }
  hand = newHand;
 }


   public int getBlackjackValue() {


     int val;      
     boolean ace;  
     int cards;    

     val = 0;
     ace = false;
     cards = getCardCount();

     for ( int i = 0;  i &lt; cards;  i++ ) {

         Card card;     
         int cardVal;  
         card = getCard(i);
         cardVal = card.getRank();  
         if (cardVal &gt; 10) {
             cardVal = 10;   
         }
         if (cardVal == 1) {
             ace = true;     
         }
         val = val + cardVal;
      } 

      if ( ace == true  &amp;&amp;  val + 10 &lt;= 21 ){
          val = val + 10;


      }
      return val;
 }
}
</code></pre>
