# get-random-values

> `window.crypto.getRandomValues` with fallback to Node.js crypto

Latest version **5.0.1** (published 2026-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install get-random-values
pnpm add get-random-values
yarn add get-random-values
bun add get-random-values
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2026-08-23 |
| First published | 2014-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | 22 \|\| >=24 |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 18 |
| Author | Kenan Yildirim <kenan@kenany.me> (https://kenany.me/) |
| Maintainers | kenan |
| Keywords | crypto |

## Links

- npm: https://www.npmjs.com/package/get-random-values
- Repository: https://github.com/kenany/get-random-values
- npm.io page: https://npm.io/package/get-random-values

## Dependencies (1)

- [window-or-global](https://npm.io/package/window-or-global.md) ^1.0.1

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 5.0.1 (latest) — 2026-08-23
- 5.0.0 — 2026-05-13
- 4.1.2 — 2026-04-13
- 4.1.1 — 2026-01-20
- 4.1.0 — 2025-10-15
- 4.0.0 — 2025-08-13
- 3.0.0 — 2023-09-21
- 2.1.0 — 2023-03-26
- 2.0.0 — 2022-06-25
- 1.2.2 — 2020-08-25
- 1.2.1 — 2020-08-25
- 1.2.0 — 2016-01-08
- 1.1.1 — 2014-09-18
- 1.1.0 — 2014-09-05
- 1.0.1 — 2014-08-07
- … 1 more at https://npm.io/package/get-random-values/versions

## README

# get-random-values

`window.crypto.getRandomValues` or `window.msCrypto.getRandomValues` or
`require('crypto').randomBytes` or an _Error_.

## Example

``` javascript
const getRandomValues = require('get-random-values');

const array = new Uint32Array(10);
getRandomValues(array);
// => [
// =>   183,
// =>   76,
// =>   18,
// =>   177,
// =>   73,
// =>   9,
// =>   50,
// =>   248,
// =>   216,
// =>   104
// => ]
```

## Installation

``` bash
$ npm install get-random-values
```

## API

``` javascript
const getRandomValues = require('get-random-values');
```

### `getRandomValues(buf)`

Fills integer-based _TypedArray_ `buf` with cryptographically random numbers.
Checks for and uses the first of the following:

  - `window.crypto.getRandomValues`
  - `window.msCrypto.getRandomValues`
  - Node.js crypto

If none of the above are available, then an _Error_ is thrown.

Throws _QuotaExceededError_ if `buf.length > 65536` (even if Node.js crypto,
which doesn't have that limit, is being used).

`buf` **must** be a _Uint8Array_ if Node.js crypto is used, otherwise a
_TypeError_ will be thrown.

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