Created
June 6, 2024 21:48
-
-
Save maxsei/179f7c968323d1dc7af101ce66f01c33 to your computer and use it in GitHub Desktop.
random string generator golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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