es-toolkit/docs/reference/math/random.md
ynnsuis / 장윤수 65a65ea24d
feat(random): Adds a function that generates a random floating-point number between the minimum and maximum. (#53)
* 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
2024-06-15 15:20:54 +09:00

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.