Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created June 6, 2024 21:48
Show Gist options
  • Save maxsei/179f7c968323d1dc7af101ce66f01c33 to your computer and use it in GitHub Desktop.
Save maxsei/179f7c968323d1dc7af101ce66f01c33 to your computer and use it in GitHub Desktop.
random string generator golang
pacakge main
import (
"math/rand"
"unicode"
)
func randomString(n int) string {
res := make([]rune, n)
letters := unicode.Letter.R16[0]
for i := range res {
res[i] = rune(uint16(rand.Uint32()%uint32(letters.Hi-letters.Lo)) + letters.Lo)
}
return string(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment