获取指定长度的随机字符串

// GetRandomStr 返回随机字符串
func GetRandomStr(l int) string {
    var A2Z []string
    var a2z []string
    var z2n []string
    var total []string
    for _, i := range Range(65, 91) {
        A2Z = append(A2Z, string(rune(i)))
    }
    total = append(total, A2Z...)
    for _, j := range Range(97, 123) {
        a2z = append(a2z, string(rune(j)))
    }
    total = append(total, a2z...)
    for _, k := range Range(48, 58) {
        z2n = append(z2n, string(rune(k)))
    }
    total = append(total, z2n...)
    var ranStr string
    rand.Seed(time.Now().UnixNano())
    for i := 0; i < l; i++ {
        ranStr = ranStr + total[rand.Intn(len(total))]
    }
    return ranStr
}

你可能感兴趣的:(获取指定长度的随机字符串)