title: Generate 6-digit Verification Code with Golang?
body: <p>Generate 6-digit code for phone verification,
  The following is a very simple approach that I have used</p>
  
  <pre><code>package main
  
  import ( 
      "fmt"
      "math/rand"
      "time"
  )        
  
  var randowCodes = [...]byte{
      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  }        
  
  func main() {
      var r *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
  
      for i := 0; i &lt; 3; i++ {
          var pwd []byte = make([]byte, 6)
  
          for j := 0; j &lt; 6; j++ {
              index := r.Int() % len(randowCodes)
  
              pwd[j] = randowCodes[index]
          }
  
          fmt.Printf("%s\n", string(pwd))                                                                  
      }    
  } 
  </code></pre>
  
  <p>Do you have a better way to do this？</p>