// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.Random;

public class Rand1to13 {
   private static Random rng;
   private boolean[] used;
   private int nused;
   public Rand1to13() {
      rng = new Random();
      used = new boolean[13];
      nused = 0;
   }
   public int nextValue() throws Exception {
      if(nused >= 13) {
         throw new Exception("No unused numbers available");
      }
      int v;
      do {
         v = 1 + rng.nextInt(13);
      } while(used[v-1]);
      used[v-1] = true;
      nused++;
      return v;
   }
   public static void main(String[] args) throws Exception {
      Rand1to13 ran = new Rand1to13();
      for(;;) {
         System.out.println(ran.nextValue());
      }
   }
}
