🌱
Sprout
Github
  • About
  • Roadmap to Sprout v1.0
  • Migration from Sprig
  • Introduction
    • Getting Started
    • Templating Conventions
  • Features
    • Loader System (Registry)
    • Loader System (Registry Group)
    • Function Aliases
    • Function Notices
    • Safe Functions
  • Registries
    • List of all registries
    • Backward
    • Checksum
    • Conversion
    • Crypto
    • Encoding
    • Env
    • Filesystem
    • Maps
    • Numeric
    • Network
    • Random
    • Reflect
    • Regexp
    • SemVer
    • Slices
    • Std
    • Strings
    • Time
    • Uniqueid
  • Groups
    • List of all registry groups
    • All
    • Hermetic
  • Advanced
    • How to create a handler
    • How to create a registry
    • How to create a registry group
  • Links
    • GitHub repository
Powered by GitBook
On this page
  • randAlphaNum
  • randAlpha
  • randAscii
  • randNumeric
  • randBytes
  • randInt
Edit on GitHub
  1. Registries

Random

The Random registry provides functions to generate random numbers, strings, and other data types, useful for scenarios requiring randomness or unique identifiers.

You can easily import all the functions from the random registry by including the following import statement in your code

import "github.com/go-sprout/sprout/registry/random"

randAlphaNum

The function generates a random alphanumeric string with the specified length, combining both letters and numbers to create a unique sequence.

Signature

{{ randAlphaNum 10 }} // Output(will be different): "OnmS3BPwBl"

randAlpha

The function generates a random string consisting of only alphabetic characters (letters) with the specified length.

Signature

{{ 10 | randAlpha }} // Output(will be different): "rBxkROwxav"

randAscii

The function generates a random ASCII string of the specified length, using characters within the ASCII range 32 to 126.

Signature

{{ randAscii 10 }} // Output(will be different): "}]~>_<:^%"

randNumeric

The function generates a random numeric string consisting only of digits, with the specified length.

Signature

{{ randNumeric 10 }} // Output(will be different): "3269896295"

randBytes

The function generates a random byte array of the specified length and returns it as a Base64 encoded string.

Signature

{{ randBytes 16 }} // Output(will be different): "c3RhY2thYnVzZSByb2NrcyE="

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 1 10 }} // Output(will be different): 5
PreviousNetworkNextReflect

Last updated 5 months ago

RandAlphaNumeric(count int) string
RandAlpha(count int) string
RandAscii(count int) string
RandNumeric(count int) string
RandBytes(count int) (string, error)
RandInt(min, max int) int