title: How to seed GUID generation?
body: <p>What would be the easiest way to code a function in .NET to generate a GUID based on a seed so that I can have greater confidence about its uniqueness?</p>
  
  <pre><code>string GenerateSeededGuid(int seed) { /* code here */ }
  </code></pre>
  
  <p>Ideally, the seed would come from <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa379942%28v=vs.85%29.aspx" rel="noreferrer">CryptGenRandom</a> which describes its random number generation as follows:</p>
  
  <blockquote>
    <p>The data produced by this function is cryptographically random. It is
    far more random than the data generated by the typical random number
    generator such as the one shipped with your C compiler.</p>
    
    <p>This function is often used to generate random <em>initialization vectors</em>
    and <em>salt values</em>.</p>
    
    <p>Software random number generators work in fundamentally the same way.
    They start with a random number, known as the seed, and then use an
    algorithm to generate a pseudo-random sequence of bits based on it.
    The most difficult part of this process is to get a seed that is truly
    random. This is usually based on user input latency, or the jitter
    from one or more hardware components.</p>
    
    <p>With Microsoft CSPs, <strong>CryptGenRandom</strong> uses the same random number
    generator used by other security components. This allows numerous
    processes to contribute to a system-wide seed. CryptoAPI stores an
    intermediate random seed with every user. To form the seed for the
    random number generator, a calling application supplies bits it might
    have—for instance, mouse or keyboard timing input—that are then
    combined with both the stored seed and various system data and user
    data such as the process ID and thread ID, the system clock, the
    system time, the system counter, memory status, free disk clusters,
    the hashed user environment block. This result is used to seed the
    pseudorandom number generator (PRNG). [...] If an application has access to a good random source, it can
    fill the <em>pbBuffer</em> buffer with some random data before calling
    <strong>CryptGenRandom</strong>. The CSP then uses this data to further randomize its
    internal seed. It is acceptable to omit the step of initializing the
    <em>pbBuffer</em> buffer before calling <strong>CryptGenRandom</strong>.</p>
  </blockquote>