Skip to content

Instantly share code, notes, and snippets.

@alec-c4
Created September 24, 2016 21:27
Show Gist options
  • Save alec-c4/4e146a7d9a5d363c958252ff209917e6 to your computer and use it in GitHub Desktop.
Save alec-c4/4e146a7d9a5d363c958252ff209917e6 to your computer and use it in GitHub Desktop.
defmodule Pin do
def generate(length \\ 4) when is_integer(length) and length >= 0 do
Enum.join(gen_pin(length))
end
defp gen_pin(1) do
[:rand.uniform(9)]
end
defp gen_pin(length) do
gen_pin(length - 1) ++ [:rand.uniform(9)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment