Advertisement
EXTREMEXPLOIT

Random Integer

Dec 2nd, 2020
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function prngInt() { return Math.floor(Math.random() * 256); }
  2. function showVal(x) { return console.log("Value Obtained: " + x); }
  3.  
  4. function getPseudoRandomInt() {
  5.     function promiseBehaviour(resolve, reject) {
  6.         setTimeout(() => resolve(prngInt()), 1000)
  7.     }
  8.  
  9.     return new Promise(promiseBehaviour);
  10. }
  11.  
  12. function getRandomInt() {
  13.   return new Promise(function (resolve, reject) {
  14.         var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
  15.     var xhr = new XMLHttpRequest();
  16.     xhr.open('GET', 'https://qrng.anu.edu.au/API/jsonI.php?length=1&type=uint8');
  17.     xhr.onload = function () {
  18.       if (this.status >= 200 && this.status < 300) {
  19.         resolve(JSON.parse(xhr.response).data[0]);
  20.       } else { reject({
  21.           status: this.status,
  22.           statusText: xhr.statusText });
  23.       }
  24.     };
  25.     xhr.onerror = function () {
  26.       reject({
  27.         status: this.status,
  28.         statusText: xhr.statusText });
  29.     };
  30.     xhr.send();
  31.   });
  32. }
  33.  
  34. getRandomInt().then((resp) => console.log(resp));
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement