2024-06-15 10:00:20 +03:00
|
|
|
# randomInt
|
|
|
|
|
|
|
|
Generate a random integer within the given range.
|
|
|
|
|
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 10:00:20 +03:00
|
|
|
## Signature
|
|
|
|
|
|
|
|
```typescript
|
2024-06-30 06:24:38 +03:00
|
|
|
function randomInt(maximum: number): number;
|
2024-06-15 10:00:20 +03:00
|
|
|
function randomInt(minimum: number, maximum: number): number;
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
|
|
- `minimum` (`number`): The lower bound for the random integer (inclusive).
|
|
|
|
- `maximum` (`number`): The upper bound for the random integer (exclusive).
|
|
|
|
|
|
|
|
### Returns
|
|
|
|
|
|
|
|
- (`number`): A random integer within the specified range.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
const result1 = randomInt(0, 5); // Returns a random integer between 0 and 5.
|
|
|
|
const result2 = randomInt(5, 0); // If the minimum is greater than the maximum, an error is thrown
|
|
|
|
const result3 = randomInt(5, 5); // If the minimum is equal to the maximum, an error is thrown.
|
|
|
|
```
|