2024-06-15 09:20:54 +03:00
|
|
|
# random
|
|
|
|
|
2024-06-15 10:00:20 +03:00
|
|
|
Generate a random number within the given range. The number can be an integer or a decimal.
|
2024-06-15 09:20:54 +03:00
|
|
|
|
2024-06-30 06:24:38 +03:00
|
|
|
If only one argument is provided, a number between `0` and the given number is returned.
|
|
|
|
|
2024-06-15 09:20:54 +03:00
|
|
|
## Signature
|
|
|
|
|
|
|
|
```typescript
|
2024-06-30 06:24:38 +03:00
|
|
|
function random(maximum: number): number;
|
2024-06-15 09:20:54 +03:00
|
|
|
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
|
|
|
|
|
2024-06-15 10:00:20 +03:00
|
|
|
- (`number`): A random number within the specified range. The number can be an integer or a decimal.
|
2024-06-15 09:20:54 +03:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```typescript
|
2024-06-15 10:00:20 +03:00
|
|
|
const result1 = random(0, 5); // Returns a random number between 0 and 5.
|
2024-06-15 09:20:54 +03:00
|
|
|
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.
|
|
|
|
```
|