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.

random.go 475 B

1 vuosi sitten
1 vuosi sitten
12345678910111213141516171819202122232425
  1. package utils
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. func RandFloats(min, max float64) float64 {
  7. rand.Seed(time.Now().UnixNano())
  8. return min + rand.Float64()*(max-min)
  9. }
  10. func RandInt(max int) int {
  11. rand.Seed(time.Now().UnixNano()) // seed后随机数可变
  12. return rand.Intn(max) // 0-100的随机数
  13. }
  14. func RandIntRand(min, max int) int {
  15. if min >= max || min == 0 || max == 0 {
  16. if max == 0 {
  17. max = min
  18. }
  19. return max
  20. }
  21. return rand.Intn(max-min) + min
  22. }