UNPKG

@handy-common-utils/misc-utils

Version:
54 lines 2.49 kB
/** * Generates a random number based on a distribution function. * @param probabilityTransformerFunction A function that turns a random number within [0, 1) to another number. * If not provided, the identity function F(x) = x will be used. * @returns A generated random number. */ export declare function generateRandomNumber(probabilityTransformerFunction?: ((x: number) => number)): number; /** * Generates a random integer within [min, max). * @param min The inclusive lower bound. * @param max The exclusive upper bound. * @returns A random integer between min (inclusive) and max (exclusive). */ export declare function generateRandomInteger(min: number, max: number): number; /** * Generates a random boolean value. * @param probabilityOfTrue The probability of returning true, between 0 and 1. Default is 0.5. * @returns True with the specified probability, otherwise false. */ export declare function generateRandomBoolean(probabilityOfTrue?: number): boolean; /** * Picks a random element from an array. * @param array The array to pick an element from. * @returns A randomly selected element from the array, or undefined if the array is empty. */ export declare function pickRandomElement<T>(array: Array<T>): T | undefined; /** * Generates a random string using the characters provided. * @param length The length of the string to generate. * @param chars The characters to use. Defaults to alphanumeric characters. * @returns A random string. */ export declare function generateRandomStringFromChars(length: number, chars?: string): string; /** * Picks an item from an array based on weights. * @param items The items to pick from. * @param weights The weights of the items. * @returns The picked item or undefined if invalid input. */ export declare function weightedPickRandomElement<T>(items: Array<T>, weights: Array<number>): T | undefined; /** * Generates a random number following a normal (Gaussian) distribution using Box-Muller transform. * @param mean The mean of the distribution. * @param stdev The standard deviation of the distribution. * @returns A random number. */ export declare function gaussianRandom(mean?: number, stdev?: number): number; /** * Creates a seeded pseudo-random number generator (LCG). * @param seed The seed value. * @returns A function that generates random numbers in [0, 1). */ export declare function seededRandom(seed: number): () => number; //# sourceMappingURL=random.d.ts.map