RandomBytes v1.0.4 RandomBytes View Source
Generate random strings in a few different formats.
Link to this section Summary
Functions
Generates a random base16 string
Generates a random base62 string
Generates a UUID (universally unique identifier)
Link to this section Functions
Generates a random base16 string.
The result string can contain the following characters: 0-9, a-f.
The length of the result string is twice num_bytes.
Examples
iex> RandomBytes.base16
"442141c62390aa41c7c2561df1ba7c68"
iex> RandomBytes.base16(3)
"dc4bca"
Generates a random base62 string.
A base64 string typically contains the + and / characters as its extra 2 characters.
When the string will be used in a url, the + and / are usually replaced with - and _.
This function generates a base62 string, not a base64 string. It returns only letters and
numbers and doesn’t include the two special characters. The result string can contain the following
characters: A-Z, a-z, 0-9.
The length of the result string is about 4/3 of num_bytes.
Examples
iex> RandomBytes.base62
"zx1QBjpTMPuHKBHpQBv9IQ"
iex> RandomBytes.base62(30)
"io0i0jE70S2PmvBvnnE6272JbpBaoLbmxJmJXJUL"
iex> RandomBytes.base62(10)
"8BfF7DS2nxsPyg"