18 lines
427 B
Elixir
18 lines
427 B
Elixir
defmodule Bright.Utils do
|
|
@chars ~c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
@doc """
|
|
Generates a random string of the given length.
|
|
|
|
## Parameters
|
|
- length: The length of the random string to generate.
|
|
|
|
## Examples
|
|
iex> RandomString.generate(12)
|
|
"aB3dEfG7hIjK"
|
|
"""
|
|
def random_string(length \\ 12) do
|
|
for _ <- 1..length, into: "", do: <<Enum.random(@chars)>>
|
|
end
|
|
end
|