Current section
Files
Jump to
Current section
Files
lib/qrandom.ex
defmodule Qrandom do
@moduledoc """
Client for QRNG service of Australian National University.
"""
@api_url "https://qrng.anu.edu.au/API/jsonI.php?length=1&type=uint16"
@doc """
Integer random number.
"""
def int() do
case HTTPoison.get(@api_url) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
case Poison.decode(body) do
{:ok, response} ->
List.first(response["data"])
_ ->
{:error, "It's not possible to parse response from ANU QRNG API"}
end
_ ->
{:error, "It's not possible to get a random number from ANU QRNG API"}
end
end
end