Documentation ¶
Overview ¶
Package randstr provides basic functions for generating random bytes, string
Index ¶
Examples ¶
Constants ¶
View Source
const Base62Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
const Base64Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/"
View Source
const DecChars = "0123456789"
View Source
const HexChars = "0123456789abcdef"
Variables ¶
This section is empty.
Functions ¶
func Base62 ¶
Base62 generates a random Base62 string with length of n
Example: 1BsNqB61o4ztSqLC6labKGNf4MYy352X
Example ¶
for i := 0; i < 5; i++ { token := Base62(16) fmt.Println(token) }
Output: DVosDCoMShcJ3G1X uxF6JGne4gI5M74K fed6PPJPApmrt5p4 JwQ1QUMuNxPkKqgN DkiEUP32DqgBUwej
func Base64 ¶
Base64 generates a random Base64 string with length of n
Example: X02+jDDF/exDoqPg9/aXlzbUCN93GIQ5
Example ¶
for i := 0; i < 5; i++ { token := Base64(16) fmt.Println(token) }
Output: jEivTuka++OZsN4w /sbBr4mBF/lgnh3e 0jhwQUFEUYw0Y8FG CIy0D4/diZmD8WW8 40zek8qIvfn26akN
func Dec ¶ added in v1.0.5
Dec generates a random decimal number string with length of n
Example: 37110235710860781655802098192113
Example ¶
for i := 0; i < 5; i++ { token := Dec(16) fmt.Println(token) }
Output: 1232392418047380 9160917876815937 6629264107419930 0271037110897873 0337735480322223
func Hex ¶
Hex generates a random Hexadecimal string with length of n
Example: 67aab2d956bd7cc621af22cfb169cba8
Example ¶
for i := 0; i < 5; i++ { token := Hex(16) fmt.Println(token) }
Output: e83f2b2af67d616a deb3430f4e827df8 c1da2016675b8efe f41b0d7600cb15fe 685458e8c898545d
func String ¶
String generates a random string using only letters provided in the letters parameter.
If user omits letters parameter, this function will use Base62Chars instead.
Example ¶
for i := 0; i < 5; i++ { token := String(16) fmt.Println(token) }
Output: 7EbxkrHc1l3Ahmyr I5XH2gc1EEHgbmGI GlCycMpsxGkn9cDQ U2OfBDQoak0z8FwV kDX1m81u14YwEiCY
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.