蛋蛋星球-制度模式
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
917 B

  1. package egg_system_rules
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. const (
  7. KC_RAND_KIND_NUM = 0 // 纯数字
  8. KC_RAND_KIND_LOWER = 1 // 小写字母
  9. KC_RAND_KIND_UPPER = 2 // 大写字母
  10. KC_RAND_KIND_ALL = 3 // 数字、大小写字母
  11. )
  12. // OrderUUID is only num for uuid
  13. func OrderUUID(uid int) string {
  14. ustr := IntToStr(uid)
  15. tstr := Int64ToStr(time.Now().Unix())
  16. ulen := len(ustr)
  17. tlen := len(tstr)
  18. rlen := 18 - ulen - tlen
  19. krb := Krand(rlen, KC_RAND_KIND_NUM)
  20. return ustr + tstr + string(krb)
  21. }
  22. func Krand(size int, kind int) []byte {
  23. ikind, kinds, result := kind, [][]int{[]int{10, 48}, []int{26, 97}, []int{26, 65}}, make([]byte, size)
  24. isAll := kind > 2 || kind < 0
  25. rand.Seed(time.Now().UnixNano())
  26. for i := 0; i < size; i++ {
  27. if isAll { // random ikind
  28. ikind = rand.Intn(3)
  29. }
  30. scope, base := kinds[ikind][0], kinds[ikind][1]
  31. result[i] = uint8(base + rand.Intn(scope))
  32. }
  33. return result
  34. }