randomizer v1.1.1 Randomizer

Random string generator

Link to this section Summary

Types

Defines random-string types

Functions

Generates a string based on random characters of a given length.

Generates a random string of words

Link to this section Types

Specs

type() :: :all | :alpha | :downcase | :numeric | :upcase

Defines random-string types

  • :all - random string of both letters and numbers
  • :alpha - random string of letters
  • :downcase - random string of lowercase, non-numeric characters
  • :numeric - random string of numbers
  • :upcase - random string of uppercase, non-numeric characters

Link to this section Functions

Link to this function

generate!(length, type \\ :all)

Specs

generate!(pos_integer(), type()) :: String.t()

Generates a string based on random characters of a given length.

Raises an error when passed a non-supported type

Examples

iex> Randomizer.generate!(20)
"PEeAPSFmEIxJDVeN8ioH"

iex> Randomizer.generate!(15, :alpha)
"PEbDWKRCKJVWkfp"

iex> Randomizer.generate!(30, :downcase)
"nqvvrbvkhciwzfbcocysvbdiyrcqyd"

iex> Randomizer.generate!(10, :numeric)
"7721725515"

iex> Randomizer.generate!(25, :upcase)
"CZAIDPFTRZNGNKETOZCJNUCRUTXTYX"
Link to this function

words!(length, opts \\ [])

Generates a random string of words

Options

  • :dictionary - Path to an alternative dictionary file

You can also put this into your application config.

Example

# config/config.exs
use Config
config :randomizer, dictionary: "/usr/share/dict/words"

# iex
iex> Randomizer.words!(3)
"relates mine incomplete"