Created
February 26, 2015 17:07
-
-
Save whoisstan/9908350ea17543e2a651 to your computer and use it in GitHub Desktop.
Random Number generator using the ANU Quantum Random Numbers Server
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recently wrote a Python version using generators, check out the demo: https://git.io/randquantum