title: Behaviour of SecureRandom
body: <p>Even though after following many articles on <code>SecureRandom</code>, I encountered a doubt with the usage of <code>SecureRandom</code> Security API in Java. In the below example .</p>
  
  <pre><code>public class SecureRandomNumber {
  public static void main(String[] args) throws NoSuchAlgorithmException {
  
      TreeSet&lt;Integer&gt; secure = new TreeSet&lt;Integer&gt;();
      TreeSet&lt;Integer&gt; unSecure = new TreeSet&lt;Integer&gt;();
      SecureRandom sr = new SecureRandom();
      byte[] sbuf = sr.generateSeed(8);
      ByteBuffer bb = ByteBuffer.wrap(sbuf);
      long d = bb.getLong();
      sr.setSeed(d);
  
      Random r = new Random();
      r.setSeed(System.nanoTime());
      for (int k = 0; k &lt; 99999; k++) {
          int i = sr.nextInt();
          if (!secure.add(i)) {
              System.out.println("Repeated Secure Random Number");
          } else {
  //              System.out.println("************Unique***********");
          }
          int j = r.nextInt();
  
          if (!unSecure.add(j)) {
              System.out.println("Repeated UnSecure Random Number");
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When I run this program I do not find any additional benefit of using a <code>SecureRandom</code> as it almost gives the same result. </p>
  
  <p>Can anyone let me know if I am doing the right thing here? </p>