mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-11 20:59:47 +03:00
65a65ea24d
* feat(random): Add generating a random floating-point number between min and max * test(random) : Add tests for random function * feat : Add random function to math module * test : Add benchmark for random function * refactor : Change the words min, max to minimum, maximum * docs(random) : Add docs about random function * docs(random): Add docs about random function * docs(random): Fix documentation typos * docs(random): Fix documentation typos * docs(random): Fix spacing * docs(random): Fix spacing * docs(random): Update interface heading * docs(random): Update interface heading * fix(random): Validate input parameters and throw error for invalid ranges * test(random) : Update tests for new input validation logic * docs(random) : Update documentation for new input validation logic
841 B
841 B
random
Generates a random floating-point number within a given range.
This function takes a minimum and maximum value, and returns a random floating-point number within that range.
Signature
function random(minimum: number, maximum: number): number;
Parameters
minimum
(number
): The lower bound for the random number (inclusive).maximum
(number
): The upper bound for the random number (exclusive).
Returns
- (
number
): A random floating-point number within the specified range.
Examples
const result1 = random(0, 5); // Returns a random floating-point number between 0 and 5.
const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.