/** * PRNG implementations adapted from GitHub user bryce * https://github.com/bryc/code/blob/master/jshash/PRNGs.md */ import type { BoundedOptions } from "./types"; import type { Vec } from "../types"; export interface PRNG { bool(): boolean; natural(max?: number): number; counting(max?: number): number; u8(): number; u16(): number; u32(): number; i8(): number; i16(): number; i32(): number; float(opts?: Partial): number; integer(opts?: Partial): number; dice(sides: number): number; unitVector(n: N): Vec; /** * Choose a random value from a collection of `T`. * * @param options an {@link Array} or {@link Set} of `T` */ sample(options: T[] | Set): T | undefined; /** * Remove and return a random value from a collection of `T`. * * @param options an {@link Array} or {@link Set} of `T` */ take(options: T[] | Set): T | undefined; /** * Shuffles a provided array in-place to a new, random permutation using the * Fisher-Yates algorithm. * * @param array an array of values */ permute(array: T[]): void; /** * Shuffles a provided array and returns the random permutation as a new * array using the Fisher-Yates algorithm. * * @param array array an array of values */ permutation(array: T[]): T[]; /** * Compute the number of unique permutations of a collection. * * @param set an {@link Array} or {@link Set}, or number representing its size */ permutationsOf(set: number | Array | Set): number; /** * Shuffles a provided array in-place to a new, random derangement with no * fixed points, per the algorithm described by Martínez, Conrado, * Alois Panholzer, and Helmut Prodinger: * https://epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7 * * @param array an array of values */ derange(array: T[]): void; /** * Shuffles a provided array and returns a new, random derangement with no * fixed points, per the algorithm described by Martínez, Conrado, * Alois Panholzer, and Helmut Prodinger: * https://epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7 * * @param array an array of values */ derangement(array: T[]): T[]; /** * Compute the number of unique derangements of a collection. * * @param set an {@link Array} or {@link Set}, or number representing its size */ derangementsOf(set: number | Array | Set): number; } export declare class GenericPRNG implements PRNG { #private; constructor(gen?: () => number); bool(): boolean; natural(max?: number): number; counting(max?: number): number; u8(): number; u16(): number; u32(): number; i8(): number; i16(): number; i32(): number; integer({ min, max }?: Partial): number; float({ min, max }?: Partial): number; dice(sides: number): number; unitVector(n?: N): Vec; sample(options: T[] | Set): T | undefined; take(options: T[] | Set): T | undefined; /** * Shuffles a provided array in-place to a new, random permutation using the * Fisher-Yates algorithm. * * @param array an array of values */ permute(array: T[]): void; /** * Shuffles a provided array and returns the random permutation as a new * array using the Fisher-Yates algorithm. * * @param array array an array of values */ permutation(array: T[]): T[]; permutationsOf(set: number | Array | Set): number; /** * Shuffles a provided array in-place to a new, random derangement with no * fixed points, per the algorithm described by Martínez, Conrado, * Alois Panholzer, and Helmut Prodinger: * https://epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7 * * @param array an array of values */ derange(array: T[]): void; /** * Shuffles a provided array and returns a new, random derangement with no * fixed points, per the algorithm described by Martínez, Conrado, * Alois Panholzer, and Helmut Prodinger: * https://epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7 * * @param array an array of values */ derangement(array: T[]): T[]; derangementsOf(set: number | Array | Set): number; } declare class Mulberry32 extends GenericPRNG { #private; constructor(seed: number); } declare class SFC32 extends GenericPRNG { #private; constructor(a: number, b: number, c: number, d: number); } declare class SplitMix32 extends GenericPRNG { #private; constructor(seed: number); } declare class JSF32B extends GenericPRNG { #private; constructor(a: number, b: number, c: number, d: number); } declare class GJRand32 extends GenericPRNG { #private; constructor(a: number, b: number, c: number, d: number); } export declare class Random { #private; constructor(..._: never); static Seedable: typeof Mulberry32; static SFC32: typeof SFC32; static JSF32B: typeof JSF32B; static SplitMix32: typeof SplitMix32; static Mulberry32: typeof Mulberry32; static GJRand32: typeof GJRand32; static bool(): boolean; static natural(max?: number): number; static counting(max?: number): number; static u8(): number; static u16(): number; static u32(): number; static i8(): number; static i16(): number; static i32(): number; static integer(opts?: Partial): number; static float(opts?: Partial): number; static dice(sides: number): number; static unitVector(n?: N): Vec; static sample(options: T[] | Set): T | undefined; static take(options: T[] | Set): T | undefined; /** * Shuffles a provided array in-place to a new, random permutation using the * Fisher-Yates algorithm. * * @param array an array of values */ static permute(array: T[]): void; /** * Shuffles a provided array and returns the random permutation as a new * array using the Fisher-Yates algorithm. * * @param array array an array of values */ static permutation(array: T[]): T[]; /** * Compute the number of unique permutations of a collection. * * @param set an {@link Array} or {@link Set}, or number representing its size */ static permutationsOf(set: number | Array | Set): number; /** * Shuffles a provided array in-place to a new, random derangement with no * fixed points, per the algorithm described by Martínez, Conrado, * Alois Panholzer, and Helmut Prodinger: * https://epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7 * * @param array an array of values */ static derange(array: T[]): void; /** * Shuffles a provided array and returns a new, random derangement with no * fixed points, per the algorithm described by Martínez, Conrado, * Alois Panholzer, and Helmut Prodinger: * https://epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7 * * @param array an array of values */ static derangement(array: T[]): T[]; /** * Compute the number of unique derangements of a collection. * * @param set an {@link Array} or {@link Set}, or number representing its size */ static derangementsOf(set: number | Array | Set): number; } export {};