# random-int

> Generate a random integer

Latest version **3.1.0** (published 2025-09-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install random-int
pnpm add random-int
yarn add random-int
bun add random-int
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2025-09-15 |
| First published | 2015-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 91 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | random, randomize, int, integer, number, max, min, math, generate, generator |

## Links

- npm: https://www.npmjs.com/package/random-int
- Repository: https://github.com/sindresorhus/random-int
- Homepage: https://github.com/sindresorhus/random-int#readme
- Issues: https://github.com/sindresorhus/random-int/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/random-int

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2025-09-15
- 3.0.0 — 2021-04-17
- 2.0.1 — 2019-09-14
- 2.0.0 — 2019-04-11
- 1.0.0 — 2015-06-26

## README

# random-int

> Generate a random integer

## Install

```sh
npm install random-int
```

## Usage

```js
import randomInteger from 'random-int';

randomInteger(5);
//=> 3

randomInteger(10, 100);
//=> 54
```

## API

### randomInteger(maximum?)

Returns an integer from `0` to `maximum`.

### randomInteger(minimum, maximum)

Returns an integer from `minimum` to `maximum`.

If `minimum` is greater than `maximum`, the values are swapped to return an integer from the lower value to the higher value.

#### minimum

Type: `number`\
Default: `0`

Minimum integer to return.

#### maximum

Type: `number`\
Default: `1`

Maximum integer to return.

## Related

- [random-float](https://github.com/sindresorhus/random-float) - Generate a random float
- [random-item](https://github.com/sindresorhus/random-item) - Get a random item from an array
- [random-object-key](https://github.com/sindresorhus/random-object-key) - Get a random key from an object
- [random-object-value](https://github.com/sindresorhus/random-object-value) - Get a random value from an object
- [unique-random](https://github.com/sindresorhus/unique-random) - Generate random numbers that are consecutively unique
- [unique-random-array](https://github.com/sindresorhus/unique-random-array) - Get consecutively unique elements from an array
- [crypto-random-string](https://github.com/sindresorhus/crypto-random-string) - Generate a cryptographically strong random string

---
_Source: https://npm.io/package/random-int · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
