第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
923 B

  1. package zhios_third_party_utils
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "time"
  6. )
  7. const (
  8. KC_RAND_KIND_NUM = 0 // 纯数字
  9. KC_RAND_KIND_LOWER = 1 // 小写字母
  10. KC_RAND_KIND_UPPER = 2 // 大写字母
  11. KC_RAND_KIND_ALL = 3 // 数字、大小写字母
  12. )
  13. func newUUID() *[16]byte {
  14. u := &[16]byte{}
  15. rand.Read(u[:16])
  16. u[8] = (u[8] | 0x80) & 0xBf
  17. u[6] = (u[6] | 0x40) & 0x4f
  18. return u
  19. }
  20. func UUIDString() string {
  21. u := newUUID()
  22. return fmt.Sprintf("%x-%x-%x-%x-%x", u[:4], u[4:6], u[6:8], u[8:10], u[10:])
  23. }
  24. func Krand(size int, kind int) []byte {
  25. ikind, kinds, result := kind, [][]int{[]int{10, 48}, []int{26, 97}, []int{26, 65}}, make([]byte, size)
  26. isAll := kind > 2 || kind < 0
  27. rand.Seed(time.Now().UnixNano())
  28. for i := 0; i < size; i++ {
  29. if isAll { // random ikind
  30. ikind = rand.Intn(3)
  31. }
  32. scope, base := kinds[ikind][0], kinds[ikind][1]
  33. result[i] = uint8(base + rand.Intn(scope))
  34. }
  35. return result
  36. }