<19> go random string

来源:互联网 发布:全国城市 首字母 json 编辑:程序博客网 时间:2024/04/28 08:43

利用random给数据主键生成唯一ID

// 生成: 时间戳 + 设置前缀 + 随即字符串const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"func  RandomString(pixff string, strlen int) string {rand.Seed(time.Now().UTC().UnixNano())    result := make([]byte, strlen)    for i := 0; i < strlen; i++ {        result[i] = alphanum[rand.Intn(len(alphanum))]    }    return time.Now().Format("20151212010203") + "-" + pixff + "-" + string(result)}
0 0