golang生成随机字符串

func randomStr(n int) string {
    var l = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
    rand.Seed(time.Now().UnixNano())
    b := make([]rune, n)
    length := len(l)
    for i := range b {
        b[i] = l[rand.Intn(length)]
    }
    return string(b)
}

你可能感兴趣的:(golang生成随机字符串)