Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function prngInt() { return Math.floor(Math.random() * 256); }
- function showVal(x) { return console.log("Value Obtained: " + x); }
- function getPseudoRandomInt() {
- function promiseBehaviour(resolve, reject) {
- setTimeout(() => resolve(prngInt()), 1000)
- }
- return new Promise(promiseBehaviour);
- }
- function getRandomInt() {
- return new Promise(function (resolve, reject) {
- var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
- var xhr = new XMLHttpRequest();
- xhr.open('GET', 'https://qrng.anu.edu.au/API/jsonI.php?length=1&type=uint8');
- xhr.onload = function () {
- if (this.status >= 200 && this.status < 300) {
- resolve(JSON.parse(xhr.response).data[0]);
- } else { reject({
- status: this.status,
- statusText: xhr.statusText });
- }
- };
- xhr.onerror = function () {
- reject({
- status: this.status,
- statusText: xhr.statusText });
- };
- xhr.send();
- });
- }
- getRandomInt().then((resp) => console.log(resp));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement