title: Seeding a pseudo-random number generator in C#
body: <p>I need a seed for an instance of C#'s <code>Random</code> class, and I read that most people use the current time's ticks counter for this. But that is a 64-bit value and the seed needs to be a 32-bit value. Now I thought that the <code>GetHashCode()</code> method, which returns an <code>int</code>, should provide a reasonably distributed value for its object and this may be used to avoid using only the lower 32-bits of the tick count. However, I couldn't find anything about the GetHashCode() of the <code>Int64</code> datatype.</p>
  
  <p>So, I know that it will not matter much, but will the following work as good as I think (I can't trial-and-error randomness), or maybe it works the same as using <code>(int)DateTime.Now.Ticks</code> as the seed? Or maybe it even works worse? Who can shed some light on this.</p>
  
  <pre><code>int seed = unchecked(DateTime.Now.Ticks.GetHashCode());
  Random r = new Random(seed);
  </code></pre>
  
  <p>Edit: Why I need a seed and don't just let the <code>Random()</code> constructor do the work? I need to send the seed to other clients which use the same seed for the same random sequence.</p>