utils.go 321 B

12345678910111213141516
  1. package utils
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. func RandomString(length int) string {
  7. chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  8. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  9. b := make([]byte, length)
  10. for i := range b {
  11. b[i] = chars[r.Intn(len(chars))]
  12. }
  13. return string(b)
  14. }