Packages

A client to read cinema program data from VistaConnect.

Current section

Files

Jump to
vista_client lib random.ex
Raw

lib/random.ex

defmodule VistaClient.Random do
@moduledoc """
Helper to generate random strings.
"""
@alphabet [hd('a')..hd('z'), hd('A')..hd('Z'), hd('0')..hd('9')] |> Enum.concat
@doc """
## Example
iex> VistaClient.Random.string()
"a1wvjFLn6TQ4CTtz"
iex> VistaClient.Random.string(32)
"jLFFKQv4Gh9QtxIl4FCepoQJwGkI87RI"
"""
@spec string(integer()) :: String.t()
def string(length \\ 16) do
1..length
|> Enum.map(fn _ -> Enum.random(@alphabet) end)
|> to_string()
end
end