Current section
Files
Jump to
Current section
Files
lib/cat_dog.ex
defmodule CatDog do
alias CatDog.Utils
@adjectives Utils.read_file_to_tuple("priv/adjectives.txt")
@nouns Utils.read_file_to_tuple("priv/nouns.txt")
def generate do
"#{random_elem(adjectives())} #{random_elem(nouns())}"
end
defp adjectives, do: @adjectives
defp nouns, do: @nouns
defp random_elem(tuple) do
size = tuple_size(tuple)
rand = :crypto.rand_uniform(0, size)
elem(tuple, rand)
end
end