golang 的 rabbitmq 消费项目
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.

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package utils
  2. import (
  3. crand "crypto/rand"
  4. "fmt"
  5. "github.com/syyongx/php2go"
  6. "math"
  7. "math/big"
  8. "math/rand"
  9. "time"
  10. )
  11. func RandString(l int, c ...string) string {
  12. var (
  13. chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  14. str string
  15. num *big.Int
  16. )
  17. if len(c) > 0 {
  18. chars = c[0]
  19. }
  20. chrLen := int64(len(chars))
  21. for len(str) < l {
  22. num, _ = crand.Int(crand.Reader, big.NewInt(chrLen))
  23. str += string(chars[num.Int64()])
  24. }
  25. return str
  26. }
  27. //x的y次方
  28. func RandPow(l int) int {
  29. min := int(math.Pow10(l - 1))
  30. max := int(math.Pow10(l) - 1)
  31. return php2go.Rand(min, max)
  32. }
  33. func RandNum() string {
  34. seed := time.Now().UnixNano() + rand.Int63()
  35. return fmt.Sprintf("%05v", rand.New(rand.NewSource(seed)).Int31n(1000000))
  36. }