random_string_generator v1.0.1 RandomStringGenerator View Source

A Module to generate a random string based on a given string pattern.

Link to this section Summary

Functions

Given a pattern string, returns a random generated string

Given a pattern string it shuffles it to a random order, so that it can be used for the case where the string must contain certain characters but must be generated in random order

Link to this section Functions

Link to this function generate(pattern, custom_chars \\ []) View Source
generate(String.t(), List) :: String.t()
generate(String.t(), String.t()) :: String.t()

Given a pattern string, returns a random generated string.

Examples

iex> str = RandomStringGenerator.generate("l-L-d")
iex> Regex.match?(~r/[a-z]-[A-Z]-[0-9]/, str)
true

Given a pattern string it shuffles it to a random order, so that it can be used for the case where the string must contain certain characters but must be generated in random order.

Examples

iex> pattern = "lLdp-"
iex> shuffled_pattern = RandomStringGenerator.shuffle(pattern)
iex>  String.graphemes(pattern) |> Enum.sort ==
iex>  String.graphemes(shuffled_pattern) |> Enum.sort
true