Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
403 B

2 years ago
2 years ago
  1. package Util
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. var (
  7. letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
  8. )
  9. func init() {
  10. rand.Seed(time.Now().UnixNano())
  11. }
  12. // RandomString generates a random string
  13. func RandomString(n int) string {
  14. var (
  15. b []rune
  16. i int
  17. )
  18. b = make([]rune, n)
  19. for i = range b {
  20. b[i] = letterRunes[rand.Intn(len(letterRunes))]
  21. }
  22. return string(b)
  23. }