rand.go 341 B

1234567891011121314151617181920
  1. package Utils
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "time"
  6. )
  7. func RandInt(min, max int) int {
  8. if min >= max || min == 0 || max == 0 {
  9. return max
  10. }
  11. return rand.Intn(max-min) + min
  12. }
  13. func RandCode() string {
  14. randNumber := rand.New(rand.NewSource(time.Now().UnixNano()))
  15. code := fmt.Sprintf("%06v", randNumber.Int31n(1000000))
  16. return code
  17. }