package egg_system_rules import ( "math/rand" "time" ) const ( KC_RAND_KIND_NUM = 0 // 纯数字 KC_RAND_KIND_LOWER = 1 // 小写字母 KC_RAND_KIND_UPPER = 2 // 大写字母 KC_RAND_KIND_ALL = 3 // 数字、大小写字母 ) // OrderUUID is only num for uuid func OrderUUID(uid int) string { ustr := IntToStr(uid) tstr := Int64ToStr(time.Now().Unix()) ulen := len(ustr) tlen := len(tstr) rlen := 18 - ulen - tlen krb := Krand(rlen, KC_RAND_KIND_NUM) return ustr + tstr + string(krb) } func Krand(size int, kind int) []byte { ikind, kinds, result := kind, [][]int{[]int{10, 48}, []int{26, 97}, []int{26, 65}}, make([]byte, size) isAll := kind > 2 || kind < 0 rand.Seed(time.Now().UnixNano()) for i := 0; i < size; i++ { if isAll { // random ikind ikind = rand.Intn(3) } scope, base := kinds[ikind][0], kinds[ikind][1] result[i] = uint8(base + rand.Intn(scope)) } return result }