Created
June 6, 2016 00:44
-
-
Save net/5f8fa90449b6f4ba83a143b07794d0c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Random do | |
@allowed_characters 'abcdefghijklmnopqrstuvwxyz1234567890' | |
def generate(length), do: generate(length, "") | |
def generate(0, acc), do: acc | |
def generate(length, acc), do: generate(length - 1, acc <> random_char) | |
def random_char, do: <<Enum.random(@allowed_characters)>> | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment