# uuid-random

> Fastest UUIDv4 with good RNG

Latest version **1.3.2** (published 2020-06-24) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 25/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.2 |
| Published | 2020-06-24 |
| First published | 2016-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 104 |
| Author | Wes Roberts |
| Maintainers | jchook |
| Keywords | uuid, fast, random, v4, tiny |

## Links

- npm: https://www.npmjs.com/package/uuid-random
- Repository: https://github.com/jchook/uuid-random
- Homepage: https://github.com/jchook/uuid-random#readme
- Issues: https://github.com/jchook/uuid-random/issues
- npm.io page: https://npm.io/package/uuid-random

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.3.2 (latest) — 2020-06-24
- 1.3.0 — 2019-09-15
- 1.0.9 — 2019-05-11
- 1.0.8 — 2019-04-13
- 1.0.7 — 2019-03-18
- 1.0.6 — 2017-06-20
- 1.0.5 — 2016-10-16
- 1.0.4 — 2016-10-16
- 1.0.3 — 2016-10-16
- 1.0.2 — 2016-10-16
- 1.0.1 — 2016-10-15
- 1.0.0 — 2016-02-20

## README

# uuid-random

[![MIT Licence](https://img.shields.io/badge/License-MIT-informational)](LICENSE.txt)
[![Stable](https://img.shields.io/badge/Stable-1.3.0-brightgreen)](https://github.com/jchook/uuid-random/releases)

Generate RFC-4122 compliant [random UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) (version 4) with better [statistical dispersion](https://en.wikipedia.org/wiki/Statistical_dispersion) than `Math.random()`.



## Install

```sh
npm i uuid-random
```

Or download the [latest release](https://github.com/jchook/uuid-random/releases).

## Features

  * Tiny (0.6k minified + gzipped)
  * Uses [cryptographic randomness](http://caniuse.com/#feat=getrandomvalues) when possible
  * Very fast!


## Compatability

Compatible with almost all versions of:

- Node
- Babel
- TypeScript
- Web browsers

## Performance

The included `benchmark.js` as well as [independent benchmarks](https://github.com/aarondcohen/benchmark-guid) rank this library as the _fastest_ pure JS UUID v4 generator available with cryptographically secure PRNG— almost **20x faster** than the most popular library (using latest NodeJS).

| npm package     | performance     |
|-----------------|-----------------|
| portable-uuid   | 354k ops/sec    |
| uuid            | 474k ops/sec    |
| id128           | 6.0M ops/sec    |
| **uuid-random** <small>(this)</small> | **9.7M ops/sec**  |

*Results above generated on a 4.20GHz Intel i7-7700K with Node v12.18.0*

## Why use UUID?

**U**niversally **U**nique **ID**entifiers transcend many constraints of traditional incremental integer IDs, especially in distributed systems. In UUID version 4, we essentially generate a random 128-bit value.

We do trade guaranteed uniqueness for __extremely__ probable uniqueness (you would need to do-loop `uuid()` at max speed for 73,067 years for a 50% chance of **one** collision). But for that slight cost, we may now generate valid, unique, persistent IDs on any node of a distributed system (e.g. intermittently offline or high-latency clients).

_Note, if you plan to use UUIDs for a new project, depending on your requirements, you may consider a more recent standard that addresses some of the shortcomings of UUID, such as [flake-id](https://github.com/T-PWK/flake-idgen), [nanoid](https://github.com/ai/nanoid), [cuid](https://github.com/ericelliott/cuid), or [ulid](https://github.com/ulid/spec)._


## Example Usage

### Babel

```javascript
import uuid from 'uuid-random';
uuid(); // 'f32dc9ae-7ca8-44ca-8f25-f258f7331c55'
```

### Node

```javascript
var uuid = require('uuid-random');
uuid(); // '0b99b82f-62cf-4275-88b3-de039020f14e'
```

### Browser

```html
<script src="uuid-random.min.js"></script>
<script>
  uuid(); // 'b96ab5e6-f1e8-4653-ab08-4dd82ea65778'
</script>
```

### Validate a UUID v4 String

```javascript
uuid.test('0b99b82f-62cf-4275-88b3-de039020f14e'); // true
```

### Generate Binary UUIDs

```javascript
uuid.bin(); // <Buffer 41 db 10 54 b3 61 48 50 87 f1 2f 7b 08 a5 0f 06>
```


## Contributing

Feel free to [open an issue](https://github.com/jchook/uuid-random/issues) or submit a [pull request](https://github.com/jchook/uuid-random/pulls).

## License

MIT.

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