Skip to main content

randomInt()

randomInt(min, max): number

Generate a random integer within the given bounds.

Parameters

min

number

The minimum value in the range (inclusive).

max

number

The maximum value in the range (inclusive).

Returns

number

Throws

Throws if min > max.

Example

const value = randomInt(0, 10);
// value >= 0 && value <= 10;

const value = randomInt(10, 0);
// RangeError