title: Array with 10 different random elements with no duplicate
body: <p>im trying to make an array of 10 different elements with Random(), so basically i have this</p>
  
  <pre><code>public static int[] RandomArray (int xArra[]) throws java.io.IOException {
      Random Rand = new Random();
      int nal;
  
      for (int i = 0; i &lt; xArra.length; i++) {
          nal = Rand.nextInt(11); /*I would like to make this thing work with any 
                                  numbers, for example, changing this to 50 or 100.
                                  In an array of 10 elements it should be 
                                  impossible to have a duplicate because with 
                                  11 it just prints from 1 to 10. 
                                  Thats why i put 11 here.  */  
          for ( int j = 0; j &lt; xArra.length; j++) {
              if (nal == xArra[j]) {
                  nal = Rand.nextInt(11); 
                  j=0;                  
              }                           
          }
  
          xArra[i] = nal;
  
      }           
  
      return xArra;
  
  }
  </code></pre>
  
  <p>Basically im storing a random number in nal and I run my array in a second For to check 
  this random number with the already given ones, and if its equal to any number given in the array it changes it with random again, and runs the For again checking that the new number isnt duplicated, if its not, I stored in xArra[i].</p>
  
  <p>When i run it 3 times, the results look like this:</p>
  
  <p>First run:
  8
  1
  6
  4
  3
  2
  10
  8
  9
  7</p>
  
  <p>Second run:
  9
  3
  8
  10
  7
  1
  4
  5
  9
  6</p>
  
  <p>Third run:
  3
  5
  2
  3
  6
  7
  1
  4
  10
  9</p>
  
  <p>So, as you can see i almost though i had it but it duplicates just 1 number, no 2 or 3, so basically i just want to make this thing work. I just want to print 10 random numbers with no duplicate, no repeats.</p>
  
  <p>Heres my full code:</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class ArraynoR {
  
      public static void main (String[] args) throws java.io.IOException {
          int Array[]= new int [10];
          RandomArray(Array);
          for(int i=0; i&lt;Array.length; i++){
              System.out.println("Array[" + (i + 1) + "]:" + Array[i]);   
          }
      }
  
      public static int[] RandomArray (int xArra[]) throws java.io.IOException... //up
  
  }
  </code></pre>
  
  <p>Please forgive my bad english, I hope I explained myself.</p>
  
  <p>Thanks!</p>