/*
 *  Copyright ¨ 1999, Oracle Corporation. All rights reserved.
 */

package oracle.portal.sample.v2.devguide.lottery;

public class LottoPicker {

   private final int NUMPICKS = 6;
   private final int NUMBALLS = 51;
   private int[] picks;
   private String identity;

   public LottoPicker() {
      picks = new int[NUMPICKS];
   }

   public int[] getPicks() {
      for (int i = 0; i < NUMPICKS; i++) {
         picks[i] = makePick(i);
      }
      return picks;
   }

   public void setIdentity(String identity) {
      // actually does nothing at this point
   }

   private int makePick(int pickNum) {
      return ensureUnique(pickNum, ((int)(Math.random()*(NUMBALLS-1))) + 1);
   }

   private int ensureUnique(int pickNum, int pick) {
      for (int i = 0; i < pickNum; i++) {
         if (pick == picks[i])
            return makePick(pickNum);
      }
      return pick;
   }

}
