title: Generating an array of non-repeating integers
body: <p>I'm trying to generate an array of 5 non-repeating integers in Java, but there are still repeats when I run it. Here's my code so far:</p>
  <pre><code>public int[] generateCode(){
      code[0] = (int)Math.round(Math.random()*8+1); // initialize first number so it won't be compared against 
      for(int i=1; i&lt;code.length; i++){
          code[i] = (int)Math.round(Math.random()*8)+1;
          for(int j=0; j&lt;i; j++){
              while(code[i]==code[j]){
                  code[i] = (int)Math.round(Math.random()*8)+1;
              }
          } // end inner for loop
          
      } // end outer for loop
      return code;
      
      
  } // end generateCode method
  </code></pre>
  <p>Any help is very much appreciated!</p>