title: Non repeating random integers in Java
body: <p>I'm trying to get a simple bit of java code spit out the numbers 1-6 in random order without repeating. I've manage to get it to spit out six random integers between one and six, but it only checks to see if a number is used once. Here is the code:</p>
  
  <pre><code>import java.util.Random;
  
  public class kirbyInt
  
  {
  
      public static void main(String[] args)
      {
          int num1, num2, num3, num4, num5, num6;
  
  
          Random rand = new Random();
  
          num1 = rand.nextInt((6-1) + 1) + 1;
          System.out.println(num1);
  
          num2 = rand.nextInt((6-1) + 1) + 1;
  
          if (num2 == num1)
          {
              num2 = rand.nextInt((6-1) + 1) + 1;
              System.out.println(num2);
          }
          else
          {
              System.out.println(num2);
          }
  
          num3 = rand.nextInt((6-1) + 1) + 1;
  
          if (num3 == num1 || num3 == num2)
          {
              num3 = rand.nextInt((6-1) + 1) + 1;
              System.out.println(num3);
          }
          else
          {
              System.out.println(num3);
          } 
  
          num4 = rand.nextInt((6-1) + 1) + 1;
  
          if (num4 == num1 || num4 == num2 || num4 == num3)
          {
              num4 = rand.nextInt((6-1) + 1) + 1;
              System.out.println(num4);
          }
          else
          {
              System.out.println(num4);
          } 
  
          num5 = rand.nextInt((6-1) + 1) + 1;
          if (num5 == num1 || num5 == num2 || num5 == num3 || num5 == num4)
          {
              num5 = rand.nextInt((6-1) + 1) + 1;
              System.out.println(num5);
          }
          else
          {
              System.out.println(num5);
          } 
  
          num6 = rand.nextInt((6-1) + 1) + 1;
          if (num6 == num1 || num6 == num2 || num6 == num3 || num6 == num4 || num6 == num5)
          {
              num6 = rand.nextInt((6-1) + 1) + 1;
              System.out.println(num6);
          }
          else
          {
              System.out.println(num6);
          } 
  
      }
  
  }
  </code></pre>