random.go 338 B

123456789101112131415161718
  1. package helpers
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
  7. func GenerateRandomString(n int) string {
  8. rand.Seed(time.Now().UnixNano())
  9. b := make([]rune, n)
  10. for i := range b {
  11. b[i] = letters[rand.Intn(len(letters))] // nolint:gosec
  12. }
  13. return string(b)
  14. }