We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm sure someone who knows more about json can write this code better: (Also I haven't checked this code too well!!!)
// qrng.anu.edu.au
QRND qrnd=new QRND();
void setup() {
noLoop();
for (int i=0; i<1024; i++){
int r=qrnd.nextInt();
println(r);
println(hex(r));
println(binary(r));
}
}
class QRND {
int pos;
int[] rData=new int[512];
int nextInt() {
if (pos==0) {
JSONObject json=loadJSONObject("https://" + "qrng.anu.edu.au/API/jsonI.php?length=1024&type=uint16");
String[] tok=splitTokens(json.toString(), "[,");
for (int i=0; i<512; i++) {
rData[i]=(int(trim(tok[i*2+1]))<<16) | int(trim(tok[i*2+2]));
}
}
int r=rData[pos];
pos=(pos+1) & 511;
return r;
}
}
Comments
It looks like embedded links in code get messed up, so you will have to fix the loadJASONObject() operation. Oh well, I tried.
You can paste your code inside
<pre></pre>
tags.Then replace all
:
w/:
in order to workaround this forum's URL glitch. :ar!You can also split up URL strings in your code to beat the forum.
You can check previous post related to JSON objects. For example:
https://forum.processing.org/two/search?Search=loadJSONObject
The reference also is a good way to start: https://processing.org/reference/JSONArray.html
Here is a tested example:
More in a previous discussion: https://forum.processing.org/two/discussion/comment/100492/#Comment_100492
Kf
Thanks, I'll follow up the links you gave.