title: Is there a method to generate a UUID with Go language?
body: <p>I have code that looks like this:</p>
  <pre><code>u := make([]byte, 16)
  _, err := rand.Read(u)
  if err != nil {
      return
  }
  
  u[8] = (u[8] | 0x80) &amp; 0xBF // what does this do?
  u[6] = (u[6] | 0x40) &amp; 0x4F // what does this do?
  
  return hex.EncodeToString(u)
  </code></pre>
  <p>It returns a string with a length of 32, but I don't think it is a valid UUID. If it is a real UUID, why is it a UUID, and what is the purpose of the code that modifies the value of <code>u[8]</code> and <code>u[6]</code>?</p>
  <p>Is there a better way of generating UUIDs?</p>