Documentation ¶
Index ¶
Constants ¶
View Source
const ( ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" NUMERALS = "0123456789" ALPHANUMERIC = NUMERALS + ALPHABET ErrNegativeNum = errors.Err("Number cannot be negative") ErrEmptyCharset = errors.Err("Charset cannot be empty") )
Charset of characters to use for generating random strings
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BytesFunc ¶
var B BytesFunc = func(n int, charset string) ([]byte, error) { if n <= 0 || len(charset) == 0 { panic("negative number or empty charset") } result := make([]byte, n) charnum := big.NewInt(int64(len(charset))) for i := 0; i < n; i++ { r, err := rand.Int(rand.Reader, charnum) if err != nil { return nil, err } result[i] = charset[int(r.Int64())] } return result, nil }
B generate a random bytes in gived charset
func (BytesFunc) Alphanumeric ¶
AlphanumericBytes generate random ALPHABET and numberic bytes
type StringFunc ¶
var S StringFunc = func(n int, charset string) (string, error) { b, err := B(n, charset) if err != nil { return "", err } return string(b), nil }
String is same as Bytes, return string
func (StringFunc) Alphabet ¶
func (f StringFunc) Alphabet(n int) (string, error)
Alphabet generate random ALPHABET string
func (StringFunc) Alphanumeric ¶
func (f StringFunc) Alphanumeric(n int) (string, error)
Alphanumeric generate random ALPHABET and numberic string
Click to show internal directories.
Click to hide internal directories.