Created
August 2, 2023 13:57
Revisions
-
SamJakob created this gist
Aug 2, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ const { promisify } = require('util'); const exec = promisify(require('child_process').exec); /** Returns a random byte as a floating-point decimal between 0 and 1. */ async function random() { const payload = await exec(`gpg-connect-agent "SCD RANDOM 1" /bye`); const randomBytes = payload.stdout.split('\n')[0].substr(2); const buffer = Buffer.from(randomBytes, 'utf-8'); const number = buffer.readUIntBE(0, 1); return number; } (async () => { const lowerLimit = 1; const upperLimit = parseInt(process.argv[2], 10); let rand; do { rand = (await random()) + lowerLimit; } while (rand > upperLimit); console.log(rand); })();