What is @types/seedrandom?
@types/seedrandom is a TypeScript type definition package for the seedrandom library, which is used to create seeded random number generators. This allows for reproducible random number sequences, which can be useful in simulations, games, and other applications where predictable randomness is needed.
What are @types/seedrandom's main functionalities?
Creating a Seeded Random Number Generator
This feature allows you to create a random number generator that produces the same sequence of numbers each time it is initialized with the same seed. This is useful for reproducibility in tests and simulations.
const seedrandom = require('seedrandom');
const rng = seedrandom('my-seed');
console.log(rng());
Using Different Algorithms
Seedrandom supports different algorithms for generating random numbers. This example shows how to use the 'alea' algorithm.
const seedrandom = require('seedrandom');
const rng = seedrandom('my-seed', { algorithm: 'alea' });
console.log(rng());
Generating Random Numbers in a Range
This feature demonstrates how to generate random numbers within a specific range using a seeded random number generator.
const seedrandom = require('seedrandom');
const rng = seedrandom('my-seed');
const randomInRange = (min, max) => min + rng() * (max - min);
console.log(randomInRange(1, 10));
Other packages similar to @types/seedrandom
random-seed
random-seed is another library that provides seeded random number generation. It is simpler and has fewer features compared to seedrandom, but it is still useful for basic seeded random number generation.
chance
chance is a library that provides a wide range of random data generators, including seeded random number generation. It offers more functionality than seedrandom, such as generating random names, addresses, and other data types.
random-js
random-js is a library that provides a variety of random number generators, including seeded generators. It offers more control over the random number generation process and supports multiple algorithms.
Installation
npm install --save @types/seedrandom
Summary
This package contains type definitions for seedrandom (https://github.com/davidbau/seedrandom).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/seedrandom.
declare namespace seedrandom {
type State = object;
interface Callback {
(prng?: prng, shortseed?: string, global?: boolean, state?: State): prng;
}
interface Options {
entropy?: boolean | undefined;
global?: boolean | undefined;
pass?: Callback | undefined;
state?: boolean | State | undefined;
}
}
interface prng {
(): number;
double(): number;
int32(): number;
quick(): number;
state(): seedrandom.State;
}
interface seedrandom {
(seed?: string, options?: seedrandom.Options, callback?: seedrandom.Callback): prng;
alea(seed?: string, options?: seedrandom.Options): prng;
Alea: new (seed?: string) => prng;
tychei(seed?: string, options?: seedrandom.Options): prng;
Tychei: new (seed?: string) => prng;
xor128(seed?: string, options?: seedrandom.Options): prng;
Xor128: new (seed?: string) => prng;
xor4096(seed?: string, options?: seedrandom.Options): prng;
Xor4096: new (seed?: string) => prng;
xorshift7(seed?: string, options?: seedrandom.Options): prng;
XorShift7: new (seed?: string) => prng;
xorwow(seed?: string, options?: seedrandom.Options): prng;
XorWow: new (seed?: string) => prng;
}
declare const seedrandom: seedrandom;
export = seedrandom;
Additional Details
- Last updated: Tue, 06 Jul 2021 16:34:27 GMT
- Dependencies: none
- Global values: none
Credits
These definitions were written by Kern Handa, Eugene Zaretskiy, and Martin Badin.