API Reference

seedrandom

Seeded pseudo-random number generator that replaces Math.random with reproducible, pluggable algorithms.

Official Documentation ↗
CompatibilityThis documentation covers version v3. Check the official docs for the latest API surface.

Installation

npmnpm install seedrandom
pnpmpnpm add seedrandom

Methods

Overview

seedrandom is a seeded pseudo-random number generator that can replace Math.random with reproducible, pluggable algorithms. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • seedrandom — Returns a seeded generator function that yields numbers between 0 and 1.
  • seedrandom.alea — Selects the Alea algorithm for the seeded generator.
  • seedrandom.quick — Uses a smaller, faster PRNG when statistical quality requirements are low.

Example

const seedrandom = require('seedrandom');

const rng = seedrandom('hello');
console.log(rng(), rng()); // deterministic sequence

Notes

It is designed for simulations and tests, not security. Sequences can change between major versions, so pin the version when reproducibility matters.

Verification

Seed a generator twice with the same string and confirm both produce an identical first value.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/davidbau/seedrandom@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:26.186Z.

FAQ

How do I make Math.random deterministic?
Call seedrandom("seed", { global: true }) once at startup so Math.random uses the seeded generator.
Are the generated numbers cryptographically secure?
No. seedrandom targets simulation and tests, not security; use a CSPRNG for keys and tokens.
Why did the sequence change between versions?
Algorithm revisions can alter output; pass explicit entropy with { entropy: true } or pin the package version when a sequence must be stable.