FatEcto.Utils.String (FatEcto v1.1.0)
View SourceProvides utility functions for generating random strings.
This module includes functions for generating random strings of specified lengths and from specific character sets.
Summary
Functions
Generates a random string of the specified length.
Generates a random string of the specified length using a custom character set.
Functions
@spec random(non_neg_integer()) :: binary()
Generates a random string of the specified length.
Parameters
length
: The length of the random string (default: 8).
Examples
iex> FatEcto.Utils.String.random()
"aB3dEfG1"
iex> FatEcto.Utils.String.random(12)
"xYz1aB2cD3eF"
@spec random_of(non_neg_integer(), [String.t()]) :: binary()
Generates a random string of the specified length using a custom character set.
Parameters
length
: The length of the random string.char_set
: A list of characters to use for generating the string (default: A-Z).
Examples
iex> FatEcto.Utils.String.random_of(10)
"ABCDEFGHIJ"
iex> FatEcto.Utils.String.random_of(5, ["a", "b", "c"])
"abcba"