您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

namegen.go 580B

12345678910111213141516171819202122232425262728293031323334
  1. package util
  2. import (
  3. "math/rand"
  4. "strings"
  5. )
  6. func Namegen() string {
  7. vowels := make([]string, 6)
  8. copy(vowels, strings.Split("aeiouy", ""))
  9. consonants := make([]string, 20)
  10. copy(consonants, strings.Split("bcdfghjklmnpqrstvwxz", ""))
  11. ln := rand.Intn(5) + 5
  12. vorc := rand.Intn(2)
  13. i := 0
  14. nm := make([]string, ln)
  15. for i < ln {
  16. sel, c := 0, ""
  17. if i%2 == vorc {
  18. sel = rand.Intn(6)
  19. c = vowels[sel]
  20. } else {
  21. sel = rand.Intn(20)
  22. c = consonants[sel]
  23. }
  24. if i == 0 {
  25. c = strings.ToUpper(c)
  26. }
  27. nm = append(nm, c)
  28. i++
  29. }
  30. return strings.Join(nm, "")
  31. }