Skip to content

Instantly share code, notes, and snippets.

@nyimbi
Forked from cqtsma2/anu_qrn.py
Last active April 28, 2022 03:47
Show Gist options
  • Save nyimbi/513b28981b88bead55a7ed1d3d636c96 to your computer and use it in GitHub Desktop.
Save nyimbi/513b28981b88bead55a7ed1d3d636c96 to your computer and use it in GitHub Desktop.
ANU Quantum Random Numbers API examples
#!/usr/bin/python3
# Australian National University Quantum Random Numbers Generator API running on AWS
import json
import requests
QRN_URL = "https://api.quantumnumbers.anu.edu.au/"
QRN_KEY = "txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7" # replace with your secret API-KEY
DTYPE = "uint8" # uint8, uint16, hex8, hex16
LENGTH = 10 # between 1--1024
BLOCKSIZE = 1 # between 1--10. Only needed for hex8 and hex16
params = {"length": LENGTH, "type": DTYPE, "size": BLOCKSIZE}
headers = {"x-api-key": QRN_KEY}
response = requests.get(QRN_URL, headers=headers, params=params)
if response.status_code == 200:
js = response.json()
if js["success"] == True:
print(js["data"])
else:
print(js["message"])
else:
print(f"Got an unexpected status-code: {response.status_code}")
print(response.text)
#!/bin/bash
QRN_URL=https://api.quantumnumbers.anu.edu.au/
QRN_KEY=txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7 # replace with your secret API-KEY
curl -H x-api-key:${QRN_KEY} ${QRN_URL}?type=hex16\&length=10\&size=10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment