Source File
random.go
Belonging Package
github.com/gookit/goutil/strutil
package strutilimport ()// some constant string charsconst (Numbers = "0123456789"HexChars = "0123456789abcdef" // base16AlphaBet = "abcdefghijklmnopqrstuvwxyz"AlphaBet1 = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"// AlphaNum chars, can use for base36 encodeAlphaNum = "abcdefghijklmnopqrstuvwxyz0123456789"// AlphaNum2 chars, can use for base62 encodeAlphaNum2 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"AlphaNum3 = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz")// RandomChars generate give length random chars at `a-z`func ( int) string {return buildRandomString(AlphaBet, )}// RandomCharsV2 generate give length random chars in `0-9a-z`func ( int) string {return buildRandomString(AlphaNum, )}// RandomCharsV3 generate give length random chars in `0-9a-zA-Z`func ( int) string {return buildRandomString(AlphaNum2, )}// RandWithTpl generate random string with give templatefunc ( int, string) string {if len() == 0 {= AlphaNum2}return buildRandomString(, )}// RandomString generate.//// Example://// // this will give us a 44 byte, base64 encoded output// token, err := RandomString(16) // eg: "I7S4yFZddRMxQoudLZZ-eg"func ( int) (string, error) {, := RandomBytes()return encodes.B64URL.EncodeToString(),}// RandomBytes generatefunc ( int) ([]byte, error) {return byteutil.Random()}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |