random
- Version 5.1.0
- Published
- 152 kB
- No dependencies
- MIT license
Install
npm i random
yarn add random
pnpm add random
Overview
Seedable random number generator supporting many common distributions.
Index
Variables
Functions
Classes
Type Aliases
Variables
variable _default
const _default: Random;
Functions
function createRNG
createRNG: (seedOrRNG?: SeedOrRNG) => RNG;
function mixKey
mixKey: (seed: number, key: number[]) => number[];
function processSeed
processSeed: (seed?: Seed) => number;
Classes
class ARC4RNG
class ARC4RNG extends RNG {}
class FunctionRNG
class FunctionRNG extends RNG {}
constructor
constructor(rngFn: RNGFn);
property name
readonly name: string;
method clone
clone: () => FunctionRNG;
method next
next: () => number;
class MathRandomRNG
class MathRandomRNG extends RNG {}
class Random
class Random {}
Seedable random number generator supporting many common distributions.
Random
Parameter rng
Underlying random number generator or a seed for the default PRNG. Defaults to
Math.random
.
constructor
constructor(seedOrRNG?: SeedOrRNG);
property bates
bates: (n?: number) => () => number;
Generates a [Bates distribution](https://en.wikipedia.org/wiki/Bates_distribution).
Parameter n
Number of uniform samples to average (n >= 1) {function}
property bernoulli
bernoulli: (p?: number) => () => number;
Generates a [Bernoulli distribution](https://en.wikipedia.org/wiki/Bernoulli_distribution).
Parameter p
Success probability of each trial. {function}
property binomial
binomial: (n?: number, p?: number) => () => number;
Generates a [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution).
Parameter n
Number of trials.
Parameter p
Success probability of each trial. {function}
property bool
bool: () => boolean;
Samples a uniform random boolean value.
Convence wrapper around
random.uniformBoolean()
random.boolean
{boolean}
property boolean
boolean: () => boolean;
Samples a uniform random boolean value.
Convence wrapper around
random.uniformBoolean()
{boolean}
property exponential
exponential: (lambda?: number) => () => number;
Generates an [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution).
Parameter lambda
Inverse mean (lambda > 0) {function}
property float
float: (min?: number, max?: number) => number;
Samples a uniform random floating point number, optionally specifying lower and upper bounds.
Convence wrapper around
random.uniform()
Parameter min
Lower bound (float, inclusive)
Parameter max
Upper bound (float, exclusive) {number}
property geometric
geometric: (p?: number) => () => number;
Generates a [Geometric distribution](https://en.wikipedia.org/wiki/Geometric_distribution).
Parameter p
Success probability of each trial. {function}
property int
int: (min?: number, max?: number) => number;
Samples a uniform random integer, optionally specifying lower and upper bounds.
Convence wrapper around
random.uniformInt()
Parameter min
Lower bound (integer, inclusive)
Parameter max
Upper bound (integer, inclusive) {number}
property integer
integer: (min?: number, max?: number) => number;
Samples a uniform random integer, optionally specifying lower and upper bounds.
Convence wrapper around
random.uniformInt()
random.int
Parameter min
Lower bound (integer, inclusive)
Parameter max
Upper bound (integer, inclusive) {number}
property irwinHall
irwinHall: (n?: number) => () => number;
Generates an [Irwin Hall distribution](https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution).
Parameter n
Number of uniform samples to sum (n >= 0) {function}
property logNormal
logNormal: (mu?: number, sigma?: number) => () => number;
Generates a [Log-normal distribution](https://en.wikipedia.org/wiki/Log-normal_distribution).
Parameter mu
Mean of underlying normal distribution
Parameter sigma
Standard deviation of underlying normal distribution {function}
property next
next: () => number;
Convenience wrapper around
this.rng.next()
Returns a floating point number in [0, 1).
{number}
property normal
normal: (mu?: number, sigma?: number) => () => number;
Generates a [Normal distribution](https://en.wikipedia.org/wiki/Normal_distribution).
Parameter mu
Mean
Parameter sigma
Standard deviation {function}
property pareto
pareto: (alpha?: number) => () => number;
Generates a [Pareto distribution](https://en.wikipedia.org/wiki/Pareto_distribution).
Parameter alpha
Alpha {function}
property poisson
poisson: (lambda?: number) => () => number;
Generates a [Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution).
Parameter lambda
Mean (lambda > 0) {function}
property rng
readonly rng: RNG;
{RNG} rng - Underlying pseudo-random number generator.
property uniform
uniform: (min?: number, max?: number) => IDist<number>;
Generates a [Continuous uniform distribution](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)).
Parameter min
Lower bound (float, inclusive)
Parameter max
Upper bound (float, exclusive)
property uniformBoolean
uniformBoolean: () => IDist<boolean>;
Generates a [Discrete uniform distribution](https://en.wikipedia.org/wiki/Discrete_uniform_distribution), with two possible outcomes,
true
or `false.This method is analogous to flipping a coin.
{function}
property uniformInt
uniformInt: (min?: number, max?: number) => IDist<number>;
Generates a [Discrete uniform distribution](https://en.wikipedia.org/wiki/Discrete_uniform_distribution).
Parameter min
Lower bound (integer, inclusive)
Parameter max
Upper bound (integer, inclusive) {function}
method choice
choice: <T>(array: Array<T>) => T | undefined;
Returns an item chosen uniformly at random from the given array.
Convence wrapper around
random.uniformInt()
Parameter array
Input array {T | undefined}
method clone
clone: (seedOrRNG?: SeedOrRNG) => Random;
Creates a new
Random
instance, optionally specifying parameters to set a new seed.{Random}
method use
use: (seedOrRNG: SeedOrRNG) => void;
Sets the underlying pseudorandom number generator.
Example 1
import random from 'random'random.use('example-seed')// orrandom.use(Math.random)
class RNG
abstract class RNG {}
Type Aliases
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (17)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/random
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/random)
- HTML<a href="https://www.jsdocs.io/package/random"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3448 ms. - Missing or incorrect documentation? Open an issue for this package.