Skip to content

randomInt

Generate a random integer within the given range.

If only one argument is provided, a number between 0 and the given number is returned.

Signature

typescript
function randomInt(maximum: number): number;
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
import { 
randomInt
} from 'js-utils-es/math';
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.

Source

SourceDocsTest Case

Contributors

Changelog

No recent changes

Made with ❤️

Layout Switch

Adjust the layout style of VitePress to adapt to different reading needs and screens.

Expand all
The sidebar and content area occupy the entire width of the screen.
Expand sidebar with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Expand all with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Original width
The original layout width of VitePress

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.

Spotlight

Highlight the line where the mouse is currently hovering in the content to optimize for users who may have reading and focusing difficulties.

ONOn
Turn on Spotlight.
OFFOff
Turn off Spotlight.