{"library":"seedrandom","title":"Seeded Random Number Generator","description":"Seedrandom is a JavaScript library that provides seeded pseudorandom number generators (PRNGs). It allows developers to create reproducible sequences of 'random' numbers, which is crucial for deterministic simulations, testing, and specific cryptographic applications (though caution is advised for security-sensitive contexts due to common misuse patterns). The current stable version is 3.0.5, released in late 2019, suggesting a mature but slow-moving maintenance cadence. Key differentiators include its ability to replace the global `Math.random` for debugging or testing purposes, and its inclusion of various PRNG algorithms (such as ARC4, Alea, xor128, Tyche-i) offering different performance characteristics and period lengths. It supports use in web browsers via script tags, as a Node.js module, and as an AMD module. Developers can instantiate independent PRNGs or opt to globally override `Math.random` with a seeded sequence.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install seedrandom"],"cli":null},"imports":["import seedrandom from 'seedrandom';","const seedrandom = require('seedrandom');","import Alea from 'seedrandom/lib/alea';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import seedrandom from 'seedrandom';\n\n// Create an independent, seeded PRNG instance\nconst myrng = new seedrandom('my-secret-seed');\nconsole.log('Seeded PRNG instance results (ARC4):');\nconsole.log(myrng()); // Always the same for this seed\nconsole.log(myrng()); // Always the same subsequent value\n\n// Demonstrating other PRNGs (Alea algorithm)\nimport Alea from 'seedrandom/lib/alea';\nconst aleaRng = new Alea('another-seed'); // Alea requires an explicit seed\nconsole.log('\\nSeeded PRNG instance results (Alea):');\nconsole.log(aleaRng());\nconsole.log(aleaRng.double()); // Alea can provide 56 bits of randomness\n\n// --- WARNING: Global Math.random override example ---\n// This directly modifies the global Math.random, making it predictable.\n// This should only be used for controlled testing and must be restored.\nconsole.log('\\nGlobal Math.random override (WARNING!):');\nconst originalMathRandom = Math.random; // Save original Math.random\nseedrandom('global-override-seed'); // Calling without 'new' or assignment overrides Math.random\nconsole.log(Math.random());\nconsole.log(Math.random());\n\n// Restore original Math.random after demonstration to prevent side effects\nMath.random = originalMathRandom;\nconsole.log('\\nMath.random restored to original behavior.');","lang":"javascript","description":"Demonstrates creating independent seeded PRNG instances using the default ARC4 algorithm and the Alea algorithm. Also illustrates the critical warning regarding globally overriding `Math.random`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}