random-pie
Version:
A lightweight TypeScript/JavaScript library providing Python-style random number generation and randomization utilities. This utility module implements the most common functions from Python's random module, making it intuitive for Python developers workin
44 lines (43 loc) • 2.56 kB
TypeScript
/**
* Generates a random floating-point number between 0 (inclusive) and 1 (exclusive). It is equivalent to Math.random().
* @returns {number} A random floating-point number between 0 and 1
*/
declare function rand(): number;
/**
* Generates a random floating-point number within a given range. The range is inclusive, meaning both min and max are included (min <= number <= max).
* @param {number} min The minimum value of the range
* @param {number} max The maximum value of the range
* @throws {TypeError} If min or max is not a number
* @throws {RangeError} If max is less than or equal to min
* @returns {number} A random floating-point number between min and max
*/
declare function uniform(min: number, max: number): number;
/**
* Generates a random integer from the specified range such that start <= number <= stop. If only one argument is provided,
* it generates a random integer from 0 to the given number. If two arguments are provided,
* it generates a random integer from the first argument to the second argument.
* If three arguments are provided, the first argument is the start of the range,
* the second argument is the stop of the range, and the third argument is the step of the range.
* @param {...number} args - The range parameters (start, stop, step)
* @param {number} [start=0] The start of the range
* @param {number} [stop] The stop of the range
* @param {number} [step=1] The step of the range
* @throws {Error} If the arguments count is not between 1 and 3.
* @returns {number} A random integer within the specified range
*/
declare function randInt(...args: number[]): number;
/**
* Generates a random number from the given range. The generated number will in the range start <= number < stop. If only one argument is given,
* a random number from 0 to the given number is generated. If two arguments are given,
* a random number from the first argument to the second argument is generated.
* If three arguments are given, the first argument is the start of the range,
* the second argument is the stop of the range, and the third argument is the step of the range.
* @param {...number} args - The range parameters (start, stop, step)
* @param {number} [start=0] The start of the range
* @param {number} [stop] The stop of the range
* @param {number} [step=1] The step of the range
* @throws {Error} If the arguments count is not between 1 and 3.
* @returns {number} The random number
*/
declare function randRange(...args: number[]): number;
export { rand, uniform, randInt, randRange };