UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

64 lines (63 loc) 2.18 kB
import { IRNG } from "./rng"; /** * AleaRNG is an implementation based on * https://github.com/nquinlan/better-random-numbers-for-javascript-mirror * Johannes Baagøe <baagoe@baagoe.com>, 2010 */ export declare class AleaRNG implements IRNG { private seed; private s0; private s1; private s2; private c; /** * Creates a new AleaRNG * @param seed - An optional string to seed the generation. Defaults to new Date() if not provided. */ constructor(seed?: string); /** * Resets the RNG to the original seed */ reset(): void; private sanitize; private step; private nextRand; /** * Returns a number between [min, max). Use nextInt() for integers. * @param min - The min (inclusive). Default 0. * @param max - The max (exclusive). Default 1. * @returns - A float between [min, max) */ next(min?: number, max?: number): number; /** * Returns an integer between [min, max). Use next() for floats. * @param min - The min (inclusive). Default 0. * @param max - The max (exclusive). Default 100. * @returns - An integer between [min, max) */ nextInt(min?: number, max?: number): number; /** * Returns a boolean. * @returns - Either true or false */ nextBoolean(): boolean; /** * Returns a random item from the given array. This does *not* remove the item from the array, * and multiple calls with the same array may yield the same item. If looking to randomize an array, * use shuffle(). * @param array - An array of items. * @returns - A single item from the array. */ nextItem<T>(array: T[]): T | undefined; /** * Shuffles all values inside an array. Returns a copy, and does not edit the original. * @param array - An array of items * @returns - A clone of the original array with all values shuffled. */ shuffle<T>(array: T[]): T[]; /** * Returns a copy of the AleaRNG, with the seed and current step value. * @returns - A copy of the AleaRNG */ clone(): AleaRNG; }