public class Shuffler {

    private Card[] allCards;   // representing all the cards
    private int nUsed;         // count the number of cards used

    private void shuffle_all_cards(){
	java.util.Random rnd = new java.util.Random();

	for(int i = allCards.length-1; i >=0; i--){
	    int j = rnd.nextInt(i+1);

	    Card tmp = allCards[i];
	    allCards[i] = allCards[j];
	    allCards[j] = tmp;
	}
    }
    
    /**
     *  Initialize a shuffler with nDecks decks of cards.
     */
    public Shuffler(int nDecks) {	
	//TODO: Add the necessary code here

	nUsed = 0;
	shuffle_all_cards();
    }

    /**
     *  Get a card from the shuffler.
     */    
    public Card get_one_card(){
	Card res = allCards[nUsed++];
	if (nUsed >= allCards.length * 3 / 4){
	    shuffle_all_cards();
	    nUsed = 0;
	}
	return res;
    }    
} 
