title: rand() generating the same number – even with srand(time(NULL)) in my main!
body: <p>So, I'm trying to create a random vector (think geometry, not an expandable array), and every time I call my random vector function I get the same x value, though y and z are different.</p>
  
  <pre><code>int main () {
      srand ( (unsigned)time(NULL));
      Vector&lt;double&gt; a;
      a.randvec();
      cout &lt;&lt; a &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>using the function</p>
  
  <pre><code>//random Vector
  template &lt;class T&gt;
  void Vector&lt;T&gt;::randvec()
  {
      const int min=-10, max=10;
      int randx, randy, randz;
  
      const int bucket_size = RAND_MAX/(max-min);
  
      do randx = (rand()/bucket_size)+min;
      while (randx &lt;= min &amp;&amp; randx &gt;= max);
      x = randx;
  
      do randy = (rand()/bucket_size)+min;
      while (randy &lt;= min &amp;&amp; randy &gt;= max);
      y = randy;
  
      do randz = (rand()/bucket_size)+min;
      while (randz &lt;= min &amp;&amp; randz &gt;= max);
      z = randz;
  }
  </code></pre>
  
  <p>For some reason, randx will consistently return 8, whereas the other numbers seem to be following the (pseudo) randomness perfectly.  However, if I put the call to define, say, randy before randx, randy will always return 8. </p>
  
  <p>Why is my first random number always 8? Am I seeding incorrectly?</p>