int.go 256 B

123456789101112131415
  1. package buildin
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. // RangeInt 按照指定范围生成随机数
  7. func RangeInt(min, max uint) int {
  8. if min >= max {
  9. return int(min)
  10. }
  11. rand.Seed(time.Now().UnixNano())
  12. return int(min + uint(rand.Intn(int(max-min+1))))
  13. }