2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,12 +1,6 @@
defmodule Random do
def init do
:random.seed(:erlang.now)
end
def pick_element(list) do
Enum.at(list, :random.uniform(length(list)) - 1)
end
end
Random.init
list = Enum.to_list(1..20)
IO.puts Random.pick_element(list)
iex(1)> list = Enum.to_list(1..20)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
iex(2)> Enum.random(list)
19
iex(3)> Enum.take_random(list,4)
[19, 20, 7, 15]