Skip to content

Instantly share code, notes, and snippets.

@czepluch
Created November 2, 2015 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czepluch/0f7c16413beb9546e288 to your computer and use it in GitHub Desktop.
Save czepluch/0f7c16413beb9546e288 to your computer and use it in GitHub Desktop.
def gen_list() do
gen_list([])
end
# Empty list. Adding first element
defp gen_list([]) do
gen_list([ gen_number | [] ])
end
# When list is non-empty and has less than 7 elements
defp gen_list(list) when length(list) < 7 do
n = gen_number
# Should make sure that no dublicates are created
if Enum.member?(list, n), do: gen_list(list)
gen_list( [gen_number | list] )
end
# Return list when 7 elements are in the list
defp gen_list(list) when length(list) == 7 do
list
end
#Generate a random number in the range 1 to 36
defp gen_number() do
:random.uniform(36)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment