{"id":17238861,"url":"https://github.com/sethblack/javascript-fortuna","last_synced_at":"2025-08-03T12:06:57.784Z","repository":{"id":57279568,"uuid":"110702844","full_name":"sethblack/javascript-fortuna","owner":"sethblack","description":"Javascript implementation of the Fortuna PRNG","archived":false,"fork":false,"pushed_at":"2019-03-22T21:45:44.000Z","size":155,"stargazers_count":12,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T16:21:36.975Z","etag":null,"topics":["cryptography","fortuna-prng","javascript","javascript-fortuna","prng","random","random-number-generators"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sethblack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-14T14:46:29.000Z","updated_at":"2025-02-28T21:15:33.000Z","dependencies_parsed_at":"2022-09-18T11:22:34.165Z","dependency_job_id":null,"html_url":"https://github.com/sethblack/javascript-fortuna","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethblack%2Fjavascript-fortuna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethblack%2Fjavascript-fortuna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethblack%2Fjavascript-fortuna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethblack%2Fjavascript-fortuna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sethblack","download_url":"https://codeload.github.com/sethblack/javascript-fortuna/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248404295,"owners_count":21097701,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","fortuna-prng","javascript","javascript-fortuna","prng","random","random-number-generators"],"created_at":"2024-10-15T05:46:57.146Z","updated_at":"2025-04-14T02:31:00.114Z","avatar_url":"https://github.com/sethblack.png","language":"JavaScript","readme":"# javascript-fortuna\n\nJavascript implementation of the Fortuna PRNG. \n\n## Installation\n\n`npm i javascript-fortuna`\n\n## Basic Usage\n\nThis is a quick out-of-the-box usage example. This is not how you'd use it in production if you want it to be secure, but it will give you a decent random number.\n\n```javascript\nconst fortuna = require('javascript-fortuna');\n\nfortuna.init();\nconst randomNumber = fortuna.random();\n\nconsole.log(`I picked ${randomNumber}!`);\n```\n\n## Command-line Usage\n\nJavascript Fortuna comes with a simple command-line app that will generate a single random number seeded by your local environment.\n\n```shell\n$ js-fortuna\n0.7947502068732222\n```\n\n## Advanced Usage\n\nTo reduce predictability add entropy from dynamic sytem state inforation such as CPU usage, number of active processes, availalbe ram and disk io.\n\n```javascript\nconst fortuna = require('javascript-fortuna');\nconst si = require('systeminformation');\nconst sha512 = require('js-sha512');\nconst jsspg = require('javascript-strong-password-generator');\n\nfunction entropyAccumFunction() {\n  return new Promise(async (resolve) =\u003e {\n    const cpuSpeed = await si.cpu();\n    const processes = await si.processes();\n    const disksIO = await si.disksIO();\n    const memory = await si.mem();\n\n    jsspg.entropyVal = sha512(`${JSON.stringify(cpuSpeed)}:${JSON.stringify(processes)}:${JSON.stringify(disksIO)}:${JSON.stringify(memory)}`);\n\n    console.log(`ent: ${jsspg.entropyVal}`);\n\n    resolve();\n  });\n}\n\nfunction entropyFunction() {\n  return jsspg.entropyVal;\n}\n\nlet entropyInterval = setInterval(async () =\u003e {\n  await entropyAccumFunction();\n}, 250);\n\njsspg.initialized = true;\n\nfortuna.init({ timeBasedEntropy: true, accumulateTimeout: 100, entropyFxn: entropyFunction });\n\nconst num1 = fortuna.random();\nconsole.log(`I picked ${num1}!`);\n\nsetTimeout(() =\u003e {\n  const num1 = fortuna.random();\n  console.log(`I picked ${num1}!`);\n  fortuna.stopTimer();\n  clearInterval(entropyInterval);\n}, 5000);\n```\n\n# Building for Browsers\n\nThis will generate a ./build/fortuna.min.js file for use in a web browser.\n\n```shell\n$ npm run webpack\n```\n\n## Basic Browser Usage\n\n```javascript\n\u003cscript src=\"js/fortuna.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n(function () {\n  fortuna.init();\n\n  var randomNumber = fortuna.random()\n  alert('I picked ' + randomNumber + '!');\n})();\n\u003c/script\u003e\n```\n\n# Core Concept\n\nFortuna is a method of generating random numbers using AES encryption and an environment-based seed. It is more secure than simply using Math.random().\n\n## API\n\n### `fortuna.init(options)`\n\n#### Options [{ k: v }]\n\n- entropyFxn [function fxn()]: Custom entropy function. Must return an Array or string of length fortuna.entropySz (128 by default)\n- timeBasedEntropy [bool]: Detaches the reseeding of the algorithm from the call to random().\n- accumulateTimeout [int]: The amount of time in milliseconds between each timeBasedEntropy call. Requires timeBasedEntropy to be true.\n\n### `fortuna.random()`\n\nGenerates a random floating point value (0,1).\n\nIf you need an integer between min and max you can simply\n\n```javascript\nconst min = 4;\nconst max = 10;\nconst randomInt = parseInt((fortuna.random() * (max - min)) + min);\n```\n\n# Visual Inspection\n\n![Random Pixel Test](https://github.com/sethblack/javascript-fortuna/blob/master/boAllenNoEntropy.png)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsethblack%2Fjavascript-fortuna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsethblack%2Fjavascript-fortuna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsethblack%2Fjavascript-fortuna/lists"}