title: What is optimal way to get four unique random number from 0-9?
body: <p>I want to generate four random numbers in the range of 0 to 9. It's easy to generate four random numbers with Java Random class.</p>
  
  <pre><code>    Random random = new Random();
  
      int numbers[] = new int[4];
  
      for(int i=0;i&lt;4;i++){
  
          numbers[i] = random.nextInt(10);
  
      }
  </code></pre>
  
  <p>With this, I can get an array of four numbers easily like, <strong>9369</strong>, <strong>4702</strong> etc.
  In this case there may be possibility of a number to be repeated in four numbers and I don't want such repeat in numbers.</p>
  
  <p>Here, I want to get all four digit in above array to be unique so that I can get output like <strong>9543</strong>, <strong>1234</strong> etc.</p>
  
  <p>For this, I have thought following way.</p>
  
  <ol>
  <li>Generate a random number and assigned as first number.</li>
  <li>Generate a random number and check with first number if different assigned as second number else generate random number again and repeat and so on.</li>
  </ol>
  
  <p>Is there any better way than above method so that I can get four unique random numbers easily and quickly ?</p>
  
  <p>Any kind of suggestion is appreciated.</p>