title: Creating a 4 digit Random Number using java with no repetition in digits
body: <p>I wrote a code using java to create a random 4 digit number with no repetition of digits, the code I wrote is given below :-<br> </p>
  
  <pre><code>Random r = new Random();
  d1 = r.nextInt(9);
  d2 = r.nextInt(9);
  d3 = r.nextInt(9);
  d4 = r.nextInt(9);
  while(d1==d2||d1==d3||d1==d4||d2==d3||d2==d4||d3==d4)
  {
      if(d1==d2||d2==d3||d2==d4)
      {
          d2 = r.nextInt(9);
      }
      if(d1==d3||d2==d3||d3==d4)
      {
          d3 = r.nextInt(9);
      }
      if(d1==d4||d2==d4||d3==d4)
      {
          d4 = r.nextInt(9);
      }
  }   
  System.out.println(d1+""+d2+""+d3+""+d4);
  </code></pre>
  
  <p><br>
  here are the test cases(generated from <code>System.out.println(R1+""+R2+""+R3+""+R4);</code>) are as following :-<br></p>
  
  <pre><code> 0123 |  OK as required
   1234 |  OK as required
   2123 |  not OK because 2 is present more than one time 
   9870 |  OK as required
   0444 |  not OK because 4 is present more than one time
  </code></pre>
  
  <p><br>
  Now My question here is, that if there is some better way to do this. If I could enhance it in some way?
  <br></p>