@freeword/meta
Version:
Meta package for Freeword: exports all core types, constants, and utilities from the src/ directory.
202 lines • 12 kB
TypeScript
import { type AleaPRNGenerator as PRNGenerator } from 'esm-seedrandom';
export type RNGSeed = string;
export type RNGSpecQ = RNGSeed | RNGFunction;
export type RNGSpec = RNGSeed | RNGFunction | undefined;
export type RNGFunction = () => number;
export interface HiLo {
lo?: number | undefined;
hi?: number | undefined;
}
export interface CharHiLo {
lo?: string | undefined;
hi?: string | undefined;
}
export interface HiLoCt extends HiLo {
count: number;
}
export interface CharHiLoCt extends CharHiLo {
count: number;
}
export interface HiLoSeed extends HiLo {
seed: RNGSeed;
}
export interface HiLoCtSeed extends HiLoCt {
seed: RNGSeed;
}
/** The possible reasons for a throwable error */
export type RNGGist = 'badSeed' | 'badRNG';
export type CharCode = number;
export declare const CHARCODE_0: number;
export declare const CHARCODE_9: number;
export declare const CHARCODE_A: number;
export declare const CHARCODE_Z: number;
export declare const CHARCODE_a: number;
export declare const CHARCODE_z: number;
export declare class BaseRandomFactory {
readonly rng: RNGFunction;
constructor(rng: RNGFunction);
static make<CT extends {
new (rng: RNGFunction): RandomFactory;
rngFor(rng?: RNGSpec): RNGFunction;
}>(this: CT, rngspec?: RNGSpec | undefined): RandomFactory;
static rngFor(rngspec?: RNGSpec): RNGFunction;
protected static _seededRNG(seed: string): RNGFunction;
/** Random float, `0 <= x < 1` */
rand01(): number;
/** Random float, `lo <= x < hi` */
rand({ lo, hi: hiIn }?: HiLo): number;
/** Random integer, `lo <= x <= hi` */
int(opts?: HiLo): number;
/** Random integer, `0 <= x <= 2^32 - 1`. On some factories this is more efficient than `int({ hi: MAX_UINT32 })`. */
uint32(): number;
/** Random integer, `0 <= x <= 2^32 - 1`. On some factories this is more efficient than `int({ hi: MAX_UINT32 })`. */
sint32(): number;
/** Random boolean */
bool(): boolean;
/** Random character `loCharCode <= x < hiCharCode` */
char({ lo, hi }?: HiLo): string;
/** Random character `loChar <= x < hiChar` */
charBetween({ lo: loChar, hi: hiChar }?: CharHiLo): string;
/** Random lower-case letter `'a'…'z'` */
lower(): string;
/** Random upper-case letter `'A'…'Z'` */
upper(): string;
/** Random letter `'A'…'Z'` */
azAZ(): string;
/** Random character `'0'..'9'…'A'..'Z'…'a'…'z'` */
azAZ09(): string;
/** Random numeral `'0'…'9'` */
numeral(): string;
/** Stream of `count` random characters, `lo <= x <= hi` */
charsStar(opts: HiLoCt): Generator<string, void, unknown>;
/** Stream of `count` random characters, `lo <= char <= hi` */
charsBetweenStar({ lo, hi, ...opts }: CharHiLoCt): Generator<string, void, unknown>;
lowersStar(count: number): Generator<string, void, unknown>;
uppersStar(count: number): Generator<string, void, unknown>;
numeralsStar(count: number): Generator<string, void, unknown>;
azAZStar(count: number): Generator<string, void, unknown>;
azAZ09Star(count: number): Generator<string, void, unknown>;
/** Random float, `0 <= x < 1`. @note: this makes a new factory for each call. But if you're making enough numbers to matter, you should choose one of the subclasses anduse the stream methods. */
static rand01(rngspec?: RNGSpec): number;
/** Random float, `lo <= x < hi`. @note: this makes a new factory for each call. But if you're making enough numbers to matter, you should choose one of the subclasses anduse the stream methods. */
static rand(opts?: HiLo, rngspec?: RNGSpec): number;
/** Random integer, `lo <= x <= hi`. @note: this makes a new factory for each call. But if you're making enough numbers to matter, you should choose one of the subclasses anduse the stream methods. */
static int(opts?: HiLo, rngspec?: RNGSpec): number;
/** Random integer, `0 <= x <= 2^32 - 1`. Some subclasses can do this more efficiently. @note: this makes a new factory for each call. But if you're making enough numbers to matter, you should choose one of the subclasses anduse the stream methods. */
static uint32(rngspec?: RNGSpec): number;
/** Random integer, `-2^31 <= x <= 2^31 - 1`. Some subclasses can do this more efficiently. @note: this makes a new factory for each call. But if you're making enough numbers to matter, you should choose one of the subclasses anduse the stream methods. */
static sint32(rngspec?: RNGSpec): number;
/** Random float, `lo <= x < hi`, with only 32 bits of randomness guaranteed. Some subclasses can do this more efficiently.@note: this makes a new factory for each call. But if you're making enough numbers to matter, you should choose one of the subclasses anduse the stream methods. */
static loose01(rngspec?: RNGSpec): number;
/** Stream of `count` random numbers, `0 <= x < 1` */
rand01sStar(count: number): Generator<number, undefined, number | undefined>;
/** Stream of `count` random numbers, `lo <= x < hi` (0 and lo + 1 by default) */
randsStar(opts: HiLoCt): Generator<number, undefined, number | undefined>;
/** Stream of `count` random integers, `lo <= x <= hi` -- (by default, `lo = 0` and `hi = lo + 9`) */
intsStar(opts: HiLoCt): Generator<number, undefined, number | undefined>;
/** Stream of `count` random integers, `0 <= x <= 2^32 - 1`. (Some subclasses can be more efficient at this than `IntsStar`.) */
uint32sStar(count: number): Generator<number, undefined, number | undefined>;
/** Stream of `count` random integers, `0 <= x <= 2^32 - 1`. (Some subclasses can be more efficient at this than `IntsStar`.) */
sint32sStar(count: number): Generator<number, undefined, number | undefined>;
/** Stream of `count` random numbers with **32 bits of randomness**, `0 <= x < 1`. (Some subclasses can be more efficient if only 32 bits of randomness are needed.)
*/
loose01sStar(count: number): Generator<number, undefined, number | undefined>;
/** Stream of `count` random numbers with **32 bits of randomness**, `lo <= x < hi`. (Some subclasses can be more efficient if only 32 bits of randomness are needed.)
* (Some subclasses can be more efficient if only 32 bits of randomness are needed.
*/
loosesStar(opts: HiLoCt): Generator<number, undefined, number | undefined>;
/** Array of `count` random numbers, `0 <= x < 1` */
rand01s(count: number): number[];
/** Array of `count` random numbers, `lo <= x < hi` */
rands(opts: HiLoCt): number[];
/** Array of `count` random integers, `lo <= x <= hi` */
randInts(opts: HiLoCt): number[];
/** Array of `count` random integers, `0 <= x <= 2^32 - 1` */
randUint32s(count: number): number[];
/** Uint32Array of `count` random integers, `0 <= x < 2^32 - 1` */
randUint32Array(count: number): Uint32Array;
/** Float32Array of `count` random numbers, `0 <= x < 1` */
randFloat32Array01(count: number): Float32Array;
/** Float32Array of `count` random numbers, `0 <= x < 1` */
randFloat32Array(opts: HiLoCt): Float32Array;
/** Float64Array of `count` random numbers with 56 bits of randomness, `0 <= x < 1`. **NOTE: that's 56 bits of randomness, not 64 bits**. */
randFloat64Array01(count: number): Float64Array;
/** Float64Array of `count` random numbers with 56 bits of randomness, `0 <= x < 1`. **NOTE: that's 56 bits of randomness, not 64 bits**. */
randFloat64Array(opts: HiLoCt): Float64Array;
/** Stream of `count` random numbers, `0 <= x < 1` */
static rand01sStar(count: number, rngspec?: RNGSpec): Generator<number, undefined, number | undefined>;
/** Array of `count` random numbers, `0 <= x < 1` */
static rand01s(count: number, rngspec?: RNGSpec): number[];
/** Float32Array of `count` random numbers, `0 <= x < 1` */
static randFloat32Array01(opts: HiLoCt, rngspec?: RNGSpec): Float32Array<ArrayBufferLike>;
/** Float64Array of `count` random numbers with 56 bits of randomness, `0 <= x < 1`. **NOTE: that's 56 bits of randomness, not 64 bits**. */
static randFloat64Array01(opts: HiLoCt, rngspec?: RNGSpec): Float64Array<ArrayBufferLike>;
/** Stream of `count` random numbers, `lo <= x < hi` */
static randsStar(opts: HiLoCt, rngspec?: RNGSpec): Generator<number, void, number | undefined>;
/** Array of `count` random numbers, `lo <= x < hi` */
static rands(opts: HiLoCt, rngspec?: RNGSpec): number[];
/** Float32Array of `count` random numbers, `lo <= x < hi` */
static randFloat32Array(opts: HiLoCt, rngspec?: RNGSpec): Float32Array<ArrayBufferLike>;
/** Float64Array of `count` random numbers with 56 bits of randomness, `lo <= x < hi`. **NOTE: that's 56 bits of randomness, not 64 bits**. */
static randFloat64Array(opts: HiLoCt, rngspec?: RNGSpec): Float64Array<ArrayBufferLike>;
/** Stream of `count` random integers, `lo <= x <= hi` */
static intsStar(opts: HiLoCt, rngspec?: RNGSpec): Generator<number, void, number | undefined>;
/** Array of `count` random integers, `lo <= x <= hi` */
static randInts(opts: HiLoCt, rngspec?: RNGSpec): number[];
/** Stream of `count` random integers, `0 <= x <= 2^32 - 1` */
static uint32sStar(count: number, rngspec?: RNGSpec): Generator<number, void, number | undefined>;
/** Array of `count` random integers, `0 <= x <= 2^32 - 1` */
static randUint32s(count: number, rngspec?: RNGSpec): number[];
/** Uint32Array of `count` random integers, `0 <= x < 2^32 - 1` */
static randUint32Array(count: number, rngspec?: RNGSpec): Uint32Array<ArrayBufferLike>;
RandIndicesStar(items: readonly any[] | number, opts: {
count: number;
}): Generator<number, undefined, number | undefined>;
RandChoicesStar<VT>(items: readonly VT[], opts: {
count: number;
}): Generator<VT, undefined, VT | undefined>;
/** Naive sampling function storing the already picked values in a Set.
* Performance of this function will decrease dramatically when `k` is a
* high proportion of `n`.
*/
naiveSample<VT>(items: readonly VT[], opts: {
count: number;
}): VT[];
TuplesStar<VT>(items: readonly VT[], opts: {
count: number;
itemLen: number;
}): Generator<VT[], void, unknown>;
/** Stream of `count` random sequences, each having `lo <= len <= hi` elements from `items`; by default, `lo = 1` and `hi = lo + 9`. Note: lo and hi are **inclusive**. */
SequencesStar<VT>(items: readonly VT[], opts: {
count: number;
lo?: number | undefined;
hi: number;
}): Generator<VT[], undefined, VT[] | undefined>;
RandStrsStar(substrings: readonly string[] | undefined, opts: {
count: number;
itemLen: number;
}): Generator<string, void, unknown>;
RandLenStrsStar(substrings: readonly string[] | undefined, opts: {
count: number;
lo?: number | undefined;
hi: number;
}): Generator<string, void, unknown>;
}
export declare class RandomFactory extends BaseRandomFactory {
}
export declare class SeededRandomFactory extends RandomFactory {
readonly rng: PRNGenerator;
constructor(seed: RNGSeed);
static make(seed: RNGSeed): SeededRandomFactory;
static rngFor(seed: RNGSeed): () => number;
/** Random float, `0 <= x < 1`. @note: this makes a new factory for each call */
static loose01(seed: RNGSeed): number;
/** Random integer, `0 <= x <= 2^32 - 1`. @note: this makes a new factory for each call */
static uint32(seed: RNGSeed): number;
/** Random integer, `0 <= x <= 2^32 - 1`. @note: this makes a new factory for each call */
static sint32(seed: RNGSeed): number;
loose01sStar(count: number): Generator<number, undefined, number | undefined>;
loosesStar(opts: HiLoCt): Generator<number, undefined, number | undefined>;
uint32sStar(count: number): Generator<number, undefined, number | undefined>;
}
//# sourceMappingURL=Random.d.ts.map