title: How to properly seed random number generator
body: <p>I am trying to generate a random string in Go and here is the code I have written so far:</p>
  
  <pre><code>package main
  
  import (
      "bytes"
      "fmt"
      "math/rand"
      "time"
  )
  
  func main() {
      fmt.Println(randomString(10))
  }
  
  func randomString(l int) string {
      var result bytes.Buffer
      var temp string
      for i := 0; i &lt; l; {
          if string(randInt(65, 90)) != temp {
              temp = string(randInt(65, 90))
              result.WriteString(temp)
              i++
          }
      }
      return result.String()
  }
  
  func randInt(min int, max int) int {
      rand.Seed(time.Now().UTC().UnixNano())
      return min + rand.Intn(max-min)
  }
  </code></pre>
  
  <p>My implementation is very slow. Seeding using <code>time</code> brings the same random number for a certain time, so the loop iterates again and again. How can I improve my code?</p>