//******************************************************************************
// creates carddeck and return cards till empty
//******************************************************************************

import java.lang.Math;

public  class HridayeshCardDeck {
        private boolean[]       deck; // card deck containing 52 cards

        public  HridayeshCardDeck() {
                deck = new boolean[52];
                reset();
        }

        public void reset() {
                int     i;
                for(i = 0; i < 52; i++) deck[i] = true; // initialize the card deck
        }

        public  int newCard() {
                int     i, rNum;
                int     cardsLeft;
                for(i = 0, cardsLeft = 0; i < 52; i++) {
                        if (deck[i]) cardsLeft++;
                }
                if(cardsLeft == 0) return -1;   // empty deck
                rNum = (int)(Math.random() * cardsLeft);
                for(i = 0; i < 52; i++) {
                        if (deck[i]) {
                                rNum--;
                                if (rNum < 0) {
                                        deck[i] = false;
                                        return i; // This is the rNum'th card on the deck
                                }
                        }
                }
                // GOD save us if we ever reach this place
                return -1;
        }
}

