title: Non-repeating random numbers inside array JAVA
body: <p>I would like to generate 6 numbers inside an array and at the same time, having it compared so it will not be the same or no repeating numbers. For example, I want to generate 1-2-3-4-5-6 in any order, and most importantly without repeating. So what I thought is to compare current array in generated array one by one and if the number repeats, it will re-run the method and randomize a number again so it will avoid repeating of numbers.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import javax.swing.*;
  public class NonRepeat
  {
      public static void main(String args[])
      {
          int Array[] = new int [6];
          int login = Integer.parseInt(JOptionPane.showInputDialog("ASD"));
          while(login != 0)
          {
              String output="";
  
              for(int index = 0; index&lt;6; index++)
              {
                  Array[index] = numGen();
  
                  for(int loop = 0; loop &lt;6 ; loop++)
                  {
                      if(Array[index] == Array[loop])
                      {
                          Array[index] = numGen();
                      }
                  }
  
  
              }
  
              for(int index = 0; index&lt;6; index++)
              {
                  output += Array[index] + " ";
              }
  
  
              JOptionPane.showMessageDialog(null, output);
  
          }
  
  
  
      }
  
      public static int numGen()
      {
          int random = (int)(1+Math.random()*6);
          return random;
      }
  }
  </code></pre>
  
  <p>I've been thinking it for 2 hours and still cant generate 6 numbers without repeating.
  Hope my question will be answered.</p>
  
  <p>Btw, Im new in codes so please I just want to compare it using <code>for</code> loop or <code>while</code> loop and <code>if else</code>.</p>