Generating 10 digits unique random number in java
<p>I am trying with below code to generate 10 digits unique random number. As per my req i have to create around 5000 unique numbers(ids). This is not working as expected. It also generates -ve numbers. Also sometimes one or two digits are missing in generated number resulting in 8 or 9 numbers not 10. </p>

<pre><code>public static synchronized  List generateRandomPin(){

    int START =1000000000;
    //int END = Integer.parseInt("9999999999");
    //long END = Integer.parseInt("9999999999");
    long END = 9999999999L;

    Random random = new Random();

    for (int idx = 1; idx &lt;= 3000; ++idx){
        createRandomInteger(START, END, random);
    }

    return null;
}


private static void createRandomInteger(int aStart, long aEnd, Random aRandom){
    if ( aStart &gt; aEnd ) {
      throw new IllegalArgumentException("Start cannot exceed End.");
    }
    //get the range, casting to long to avoid overflow problems
    long range = (long)aEnd - (long)aStart + 1;
    logger.info("range&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"+range);
    // compute a fraction of the range, 0 &lt;= frac &lt; range
    long fraction = (long)(range * aRandom.nextDouble());
    logger.info("fraction&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"+fraction);
    int randomNumber =  (int)(fraction + aStart);    
    logger.info("Generated : " + randomNumber);

  }
</code></pre>
