Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uuid-random

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uuid-random

Fastest UUIDv4 with good RNG

  • 1.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
176K
decreased by-9.31%
Maintainers
1
Weekly downloads
 
Created
Source

uuid-random

Generate RFC-4122 compliant random UUIDs with better statistical dispersion than Math.random().

Install

npm install uuid-random

Features

  • 0.3k minified + gzipped
  • Uses better RNG when possible
  • Works in browser or node with zero external dependencies
  • Very fast!

Performance

This is the fastest pure javascript UUID v4 generator I have found, over 5x faster than comparable libraries. After inspecting and/or testing every JS UUID package I could find (there are a ton), these were the fastest:

npm packageperformance
node-uuid370k ops/sec
portable-uuid260k ops/sec
uuid370k ops/sec
uuid-random2M ops/sec

What is UUID v4?

Universally Unique IDentifiers transcend many constraints of traditional incremental integer IDs, especially in distributed systems. With version 4, we (essentially) generate a random 128-bit value.

We do sacrifice 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).

Example Usage

Babel

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

Node

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

Browser

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

Is UUID?

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

Rationale

Random (v4) UUIDs are often better than clock-based (v1), but Math.random() sucks for uuid generation.

After digging through npm I settled on using node-uuid to take advantage of better RNG when possible. It's a great lib, but seemed too large and featured after using that neat oneliner-ish solution. So, I combined ideas from the better implementations and researched a much faster, more focused and compact uuid generator that used the best RNG available.

This library does one thing very well: generate UUID version 4.

License

MIT

Keywords

FAQs

Package last updated on 11 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc