golang生成大小写字母数字随机数

package main

import (
   "fmt"
   "math/rand"
   "time"
)

var letters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randSeq(n int) string {
   b := make([]rune, n)
   r:=rand.New(rand.NewSource(time.Now().UnixNano()))
   for i := range b {
      b[i] = letters[r.Intn(62)]
   }
   return string(b)
}

func main() {
   fmt.Println(randSeq(30))
}

按照ASCII码来生成可以参照https://github.com/mactsouk/opensource.com randomPass.go

 

你可能感兴趣的:(云开发)