Random
The Random registry provides functions to generate random numbers, strings, and other data types, useful for scenarios requiring randomness or unique identifiers.
randAlphaNum
The function generates a random alphanumeric string with the specified length, combining both letters and numbers to create a unique sequence.
Signature
RandAlphaNumeric(count int) string
{{ randAlphaNumeric 10 }} // Output: "OnmS3BPwBl" (output will vary)
randAlpha
The function generates a random string consisting of only alphabetic characters (letters) with the specified length.
Signature
RandAlpha(count int) string
{{ 10 | randAlpha }} // Output: "rBxkROwxav" (output will vary)
randAscii
The function generates a random ASCII string of the specified length, using characters within the ASCII range 32 to 126.
Signature
RandAscii(count int) string
{{ randAscii 10 }} // Output: "}]~>_<:^%" (output will vary)
randNumeric
The function generates a random numeric string consisting only of digits, with the specified length.
Signature
RandNumeric(count int) string
{{ randNumeric 10 }} // Output: "3269896295" (output will vary)
randBytes
The function generates a random byte array of the specified length and returns it as a Base64 encoded string.
Signature
RandBytes(count int) (string, error)
{{ randBytes 16 }} // Output: "c3RhY2thYnVzZSByb2NrcyE=" (output will vary)
randInt
The function generates a random integer between the specified minimum and maximum values (inclusive). It takes two parameters: min
for the minimum value and max
for the maximum value. The function then returns a random integer within this range.
Signature
RandInt(min, max int) int
{{ randInt 1 10 }} // Output: 5
Last updated