手记编程网

golang随机生成字符串

const letterBytes = "0123456789"


// RandString .
func RandString(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}


最新文章