title: How to not get the same random numbers in successive method calls in Java
body: <p>Consider the following code (using Java 1.8.0_102 and JDistLib 0.4.5):</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  import java.util.stream.IntStream;
  
  import jdistlib.Exponential;
  import jdistlib.generic.GenericDistribution;
  import jdistlib.rng.MersenneTwister;
  import jdistlib.rng.RandomEngine;
  
  
  public class RVs {
  
      public void getEV(GenericDistribution dist, int sampleSize) {
          ArrayList&lt;Double&gt; rvs = this.populateArray(dist, sampleSize);
          System.out.println(rvs);
      }
  
      public ArrayList&lt;Double&gt; populateArray(GenericDistribution dist, int sampleSize) {
          RandomEngine randomE = new MersenneTwister(System.currentTimeMillis());
          ArrayList&lt;Double&gt; rvs = new ArrayList&lt;Double&gt;();
          IntStream.range(0, sampleSize).forEach($ -&gt; rvs.add(dist.random(randomE)));
          return rvs;
      }
  
      public void test () {
          IntStream.range(0, 13).forEach($ -&gt; this.getEV(new Exponential(33.33), 10));
      }
  
  }
  </code></pre>
  
  <p>... implemented like this:</p>
  
  <pre><code>public class CallRVs {
      public static void main(String[] args) {
          RVs alpha = new RVs();
          alpha.test();
      }
  }
  </code></pre>
  
  <p>Unfortunately, this always repeats the same sequences of random numbers about 3-4 times.</p>
  
  <p>Before ending up with the code above, I tried this </p>
  
  <ul>
  <li>without setting the RandomEngine explicitly and </li>
  <li>without setting the random seed for the RandomEngine to the current time</li>
  </ul>
  
  <p>You would think, creating new RandomEngine instances with seed set to the current time should help, but no:</p>
  
  <pre><code>[22.703723551648405, 6.7092516027839855, 190.59060286639905, 1.8735125522919636, 41.022344668942665, 3.877018716199701, 21.49930713290334, 42.05773014708266, 23.00082916381309, 23.24308297023846]
  [22.334558402867305, 1.6401554044082725, 84.11326045120587, 18.165389107596983, 83.13647054950233, 32.72909304649951, 31.453740499105955, 93.5956252958078, 4.040938139470317, 19.99121603725849]
  [22.334558402867305, 1.6401554044082725, 84.11326045120587, 18.165389107596983, 83.13647054950233, 32.72909304649951, 31.453740499105955, 93.5956252958078, 4.040938139470317, 19.99121603725849]
  [22.334558402867305, 1.6401554044082725, 84.11326045120587, 18.165389107596983, 83.13647054950233, 32.72909304649951, 31.453740499105955, 93.5956252958078, 4.040938139470317, 19.99121603725849]
  [79.14217486099653, 41.08293664856576, 7.224345566610367, 127.53056431952126, 80.37600520651415, 38.4618180996009, 0.9904925074615941, 12.20987288657261, 36.530623436560845, 32.1600825790288]
  [79.14217486099653, 41.08293664856576, 7.224345566610367, 127.53056431952126, 80.37600520651415, 38.4618180996009, 0.9904925074615941, 12.20987288657261, 36.530623436560845, 32.1600825790288]
  [79.14217486099653, 41.08293664856576, 7.224345566610367, 127.53056431952126, 80.37600520651415, 38.4618180996009, 0.9904925074615941, 12.20987288657261, 36.530623436560845, 32.1600825790288]
  [79.14217486099653, 41.08293664856576, 7.224345566610367, 127.53056431952126, 80.37600520651415, 38.4618180996009, 0.9904925074615941, 12.20987288657261, 36.530623436560845, 32.1600825790288]
  [9.273608510364928, 3.489400227955458, 39.90486871467796, 0.62827300597674, 11.400150691547177, 5.284720630096435, 24.384279251275796, 16.08800783422188, 21.318680903820088, 5.974180125899405]
  [9.273608510364928, 3.489400227955458, 39.90486871467796, 0.62827300597674, 11.400150691547177, 5.284720630096435, 24.384279251275796, 16.08800783422188, 21.318680903820088, 5.974180125899405]
  [9.273608510364928, 3.489400227955458, 39.90486871467796, 0.62827300597674, 11.400150691547177, 5.284720630096435, 24.384279251275796, 16.08800783422188, 21.318680903820088, 5.974180125899405]
  [24.382314535207747, 19.911193724734368, 11.447193297362048, 0.9268859488114056, 18.486786238992774, 29.54231307250453, 17.592849710828943, 26.563616563286097, 19.548355104754787, 4.339118659323733]
  [24.382314535207747, 19.911193724734368, 11.447193297362048, 0.9268859488114056, 18.486786238992774, 29.54231307250453, 17.592849710828943, 26.563616563286097, 19.548355104754787, 4.339118659323733]
  </code></pre>
  
  <p>What is the proper way to prevent such repetitions? Locks (would make everything excessively slow, right?)? "Salting" the seed with some counter or counter with random increment (would be an extremely dirty hack the statistical consequences of which would be unclear)? </p>
  
  <p>Or am I doing something wrong? (I also get "RVs.java:22: warning: [deprecation] random(RandomEngine) in GenericDistribution has been deprecated" which might suggest that this is not the right way to do it.)</p>