Skip to content

Instantly share code, notes, and snippets.

@whoisstan
Created February 26, 2015 17:07
Show Gist options
  • Save whoisstan/9908350ea17543e2a651 to your computer and use it in GitHub Desktop.
Save whoisstan/9908350ea17543e2a651 to your computer and use it in GitHub Desktop.
Random Number generator using the ANU Quantum Random Numbers Server
module QRandom
def next
RestClient.get('http://qrng.anu.edu.au/API/jsonI.php?type=uint16&length=1'){ |response, request, result, &block|
case response.code
when 200
_json=JSON.parse(response)
if _json["success"]==true && _json["data"]
_json["data"].first || Random.rand(65535)
else
Random.rand(65535) #fallback
end
else
puts response #log problem
Random.rand(65535) #fallback
end
}
end
end
@rsvp
Copy link

rsvp commented Oct 7, 2015

Recently wrote a Python version using generators, check out the demo: https://git.io/randquantum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment