rand.go 651 B

12345678910111213141516171819202122232425262728
  1. /**
  2. #*****************************************************************************
  3. # @file rand.go
  4. # @author MakerYang(https://www.makeryang.com)
  5. # @statement 免费课程配套开源项目,任何形式收费均为盗版
  6. #*****************************************************************************
  7. */
  8. package Utils
  9. import (
  10. "fmt"
  11. "math/rand"
  12. "time"
  13. )
  14. func RandInt(min, max int) int {
  15. if min >= max || min == 0 || max == 0 {
  16. return max
  17. }
  18. return rand.Intn(max-min) + min
  19. }
  20. func RandCode() string {
  21. randNumber := rand.New(rand.NewSource(time.Now().UnixNano()))
  22. code := fmt.Sprintf("%06v", randNumber.Int31n(1000000))
  23. return code
  24. }