title: First random number after setSeed in Java always similar
body: <p>To give some context, I have been writing a basic Perlin noise implementation in Java, and when it came to implementing seeding, I had encountered a bug that I couldn't explain.</p>
  
  <p>In order to generate the same random weight vectors each time for the same seed no matter which set of coordinates' noise level is queried and in what order, I generated a new seed (<code>newSeed</code>), based on a combination of the original seed and the coordinates of the weight vector, and used this as the seed for the randomization of the weight vector by running:</p>
  
  <pre><code>rnd.setSeed(newSeed);
  weight = new NVector(2);
  weight.setElement(0, rnd.nextDouble() * 2 - 1);
  weight.setElement(1, rnd.nextDouble() * 2 - 1);
  weight.normalize()
  </code></pre>
  
  <p>Where <code>NVector</code> is a self-made class for vector mathematics.</p>
  
  <p>However, when run, the program generated very bad noise:
  <img src="https://i.stack.imgur.com/kPCqA.png" alt="Very bad noise, with vertical streaks"></p>
  
  <p>After some digging, I found that the first element of each vector was very similar (and so the first <code>nextDouble()</code> call after each <code>setSeed()</code> call) resulting in the first element of every vector in the vector grid being similar.</p>
  
  <p>This can be proved by running:</p>
  
  <pre><code>long seed = Long.valueOf(args[0]);
  int loops = Integer.valueOf(args[1]);
  double avgFirst = 0.0, avgSecond = 0.0, avgThird = 0.0;
  double lastfirst = 0.0, lastSecond = 0.0, lastThird = 0.0;
  for(int i = 0; i&lt;loops; i++)
  {
      ran.setSeed(seed + i);
      double first = ran.nextDouble();
      double second = ran.nextDouble();
      double third = ran.nextDouble();
      avgFirst += Math.abs(first - lastfirst);
      avgSecond += Math.abs(second - lastSecond);
      avgThird += Math.abs(third - lastThird);
      lastfirst = first;
      lastSecond = second;
      lastThird = third;
  }
  System.out.println("Average first difference.: " + avgFirst/loops);
  System.out.println("Average second Difference: " + avgSecond/loops);
  System.out.println("Average third Difference.: " + avgSecond/loops);
  </code></pre>
  
  <p>Which finds the average difference between the first, second and third random numbers generated after a <code>setSeed()</code> method has been called over a range of seeds as specified by the program's arguments; which for me returned these results:</p>
  
  <pre><code>C:\java Test 462454356345 10000
  Average first difference.: 7.44638117976783E-4
  Average second Difference: 0.34131692827329957
  Average third Difference.: 0.34131692827329957
  
  C:\java Test 46245445 10000
  Average first difference.: 0.0017196011123287126
  Average second Difference: 0.3416750057190849
  Average third Difference.: 0.3416750057190849
  
  C:\java Test 1 10000
  Average first difference.: 0.0021601598225344998
  Average second Difference: 0.3409914232342002
  Average third Difference.: 0.3409914232342002
  </code></pre>
  
  <p>Here you can see that the first average difference is significantly smaller than the rest, and seemingly decreasing with higher seeds.</p>
  
  <p>As such, by adding a simple dummy call to <code>nextDouble()</code> before setting the weight vector, I was able to fix my perlin noise implementation:</p>
  
  <pre><code>rnd.setSeed(newSeed);
  rnd.nextDouble();
  weight.setElement(0, rnd.nextDouble() * 2 - 1);
  weight.setElement(1, rnd.nextDouble() * 2 - 1);
  </code></pre>
  
  <p>Resulting in:</p>
  
  <p><img src="https://i.stack.imgur.com/tfEvQ.png" alt="enter image description here"></p>
  
  <p>I would like to know why this bad variation in the first call to <code>nextDouble()</code> (I have not checked other types of randomness) occurs and/or to alert people to this issue.</p>
  
  <p>Of course, it could just be an implementation error on my behalf, which I would be greatful if it were pointed out to me.</p>