Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomString ¶ added in v1.0.0
RandomString returns a random string of the given length using the provided charset. If secure is true, it uses a cryptographically secure random generator (returns error on failure). If secure is false, it uses a fast, non-cryptographically secure generator (never returns error). If charset is empty, Alphanumeric is used.
func String ¶
String returns a random string of the given length using a fast, non-cryptographically secure generator. For security-sensitive use cases, use StringWithCharset instead.
func StringWithCharset ¶
StringWithCharset returns a cryptographically secure random string of the given byte length, using the provided charset. The randomness is suitable for security-sensitive use cases. Returns an error if the system's secure random number generator fails.
Types ¶
type Charset ¶
type Charset string
Charset represents a set of characters to use for random string generation.
const ( // Alphanumeric contains all alphabetic and numeric characters (A-Z, a-z, 0-9). Alphanumeric Charset = Alphabetic + Numeric // Alphabetic contains all uppercase and lowercase English letters (A-Z, a-z). Alphabetic Charset = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // Numeric contains all decimal digits (0-9). Numeric Charset = "0123456789" // Hex contains all hexadecimal digits (0-9, a-f). Hex Charset = Numeric + "abcdef" )