
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
seed-random
Advanced tools
The 'seed-random' npm package is used to generate random numbers with a deterministic sequence based on a seed value. This is useful for scenarios where reproducibility is important, such as in simulations, games, or procedural content generation.
Basic Usage
This feature allows you to create a random number generator that produces the same sequence of numbers for a given seed. This is useful for creating reproducible results.
const seedrandom = require('seed-random');
const random = seedrandom('my-seed');
console.log(random()); // Generates a random number based on the seed
Multiple Generators
You can create multiple random number generators with different seeds, each producing its own sequence of random numbers. This is useful for managing different random processes independently.
const seedrandom = require('seed-random');
const random1 = seedrandom('seed1');
const random2 = seedrandom('seed2');
console.log(random1()); // Generates a random number based on 'seed1'
console.log(random2()); // Generates a random number based on 'seed2'
State Saving and Restoring
This feature allows you to save the state of a random number generator and restore it later. This is useful for pausing and resuming random processes without losing the sequence.
const seedrandom = require('seed-random');
const random = seedrandom('my-seed', { state: true });
const state = random.state();
console.log(random()); // Generates a random number
const newRandom = seedrandom('', { state: state });
console.log(newRandom()); // Continues the sequence from the saved state
The 'random-seed' package provides similar functionality to 'seed-random' by allowing you to generate random numbers based on a seed. It also supports saving and restoring the state of the generator. However, 'random-seed' offers additional methods for generating random integers and booleans.
The 'seedrandom' package is another alternative that provides a seeded random number generator. It supports various algorithms for random number generation and allows for saving and restoring the state. It is more feature-rich compared to 'seed-random' and is widely used in the community.
Generate random numbers with a seed, useful for reproducible tests
$ npm install seed-random
var assert = require('assert');
var seed = require('../');
var trueRandomA = seed();
var trueRandomB = seed();
assert(trueRandomA() != trueRandomB());
var fakeRandomA = seed('foo');
var fakeRandomB = seed('foo');
assert(fakeRandomA() == fakeRandomB());
var fakeRandomC = seed('foo', {entropy: true});
var fakeRandomD = seed('foo', {entropy: true});
assert(fakeRandomC() != fakeRandomD());
seed('foo', {global: true});//over-ride global Math.random
var numA = Math.random();
seed('foo', {global: true});
var numB = Math.random();
assert(numA == numB);//always true
seed.resetGlobal();//reset to default Math.random
MIT
FAQs
Generate random numbers with a seed, useful for reproducible tests
The npm package seed-random receives a total of 1,134,680 weekly downloads. As such, seed-random popularity was classified as popular.
We found that seed-random demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.