short-unique-id - v4.4.2

Short Unique ID

image depicting order and disorder

This page is part of the open source javascript library short-unique-id.

For usage examples click here.

Online (short) UUID generator

Press the buttons below to generate your short uuid codes:


Your random UUID:  

Your sequential UUID:  

Random Color generator

The ability to set a custom dictionary and length means that Short Unique ID is useful for many other cases such as this random color generator.

      // instantiate using a dictionary containing all 16 valid hex characters

      var uid = new ShortUniqueId({
        dictionary: [
          '0', '1', '2', '3',
          '4', '5', '6', '7',
          '8', '9', 'A', 'B',
          'C', 'D', 'E', 'F',

      // or using default dictionaries available since v4.3+

      var uid = new ShortUniqueId({ dictionary: 'hex' });

      // then taste the rainbow 🌈

      var color = '#' + uid.randomUUID(6) + ';';

Your random color:  

Short Unique ID (UUID) Generating Library

Tests Try short-unique-id on RunKit NPM Downloads JsDelivr Hits

9 Contributors

Tiny (4.6kB minified) no-dependency library for generating random or sequential UUID of any length with exceptionally minuscule probabilies of duplicate IDs.

const uid = new ShortUniqueId({ length: 10 });
uid(); // p0ZoB1FwH6
uid(); // mSjGCTfn8w
uid(); // yt4Xx5nHMB
// ...

For example, using the default dictionary of numbers and letters (lower and upper case):

  • if you generate a unique ID of 16 characters (half of the standard UUID of 32 characters)
  • generating 100 unique IDs per second

It would take ~10 thousand years to have a 1% probability of at least one collision!

To put this into perspective:

  • 73 years is the (global) average life expectancy of a human being
  • 120 years ago no human ever had set foot on either of the Earth's poles
  • 480 years ago Nicolaus Copernicus was still working on his theory of the Earth revolving around the Sun
  • 1000 years ago there was no such thing as government-issued paper money (and wouldn't be for about a century)
  • 5000 years ago the global population of humans was under 50 million (right now Mexico has a population of 127 million)

You can calculate duplicate/collision probabilities using the included functions:

NOTE: 👆 On these links you will also find explanations for the math used within the functions.

Open source notice

This project is open to updates by its users, I ensure that PRs are relevant to the community. In other words, if you find a bug or want a new feature, please help us by becoming one of the contributors ✌️ ! See the contributing section.

Like this module? ❤

Please consider:

📣 v4 Notice

New Features 🥳

The ability to generate UUIDs that contain a timestamp which can be extracted:

// js/ts

const uid = new ShortUniqueId();

const uidWithTimestamp = uid.stamp(32);
// GDa608f973aRCHLXQYPTbKDbjDeVsSb3

const recoveredTimestamp = uid.parseStamp(uidWithTimestamp);
// 2021-05-03T06:24:58.000Z
# cli

$ suid -s -l 42


$ suid -p lW611f30a2ky4276g3l8N7nBHI5AQ5rCiwYzU47HP2


Default dictionaries (generated on the spot to reduce memory footprint and avoid dictionary injection vulnerabilities):

  • number
  • alpha
  • alpha_lower
  • alpha_upper
  • alphanum (default when no dictionary is provided to new ShortUniqueId())
  • alphanum_lower
  • alphanum_upper
  • hex
// instantiate using one of the default dictionary strings
const uid = new ShortUniqueId({
  dictionary: 'hex', // the default

// 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f

// or change the dictionary after instantiation

// A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

Use in CLI

$ npm install -g short-unique-id

$ suid -h

# Usage:
#   node short-unique-id [OPTION]

# Options:
#   -l, --length=ARG         character length of the uid to generate.
#   -s, --stamp              include timestamp in uid (must be used with --length (-l) of 10 or more).
#   -p, --parse=ARG          extract timestamp from stamped uid (ARG).
#   -d, --dictionaryJson=ARG json file with dictionary array.
#   -h, --help               display this help

Use as module

Add to your project:

// Deno (web module) Import
import ShortUniqueId from '';

// ES6 / TypeScript Import
import ShortUniqueId from 'short-unique-id';

// Node.js require
const ShortUniqueId = require('short-unique-id');

Instantiate and use:

const uid = new ShortUniqueId();

// Random UUID

// Sequential UUID

Use in browser

<!-- Add source (minified 4.6kB) -->
<script src=""></script>

<!-- Usage -->
  // Instantiate
  var uid = new ShortUniqueId();

  // Random UUID

  // Sequential UUID


Options can be passed when instantiating uid:

const options = { ... };

const uid = new ShortUniqueId(options);

For more information take a look at the docs.

Available for

Documentation with Online Short UUID Generator

You can find the docs and online generator at:

What is the probability of generating the same id again?

This largely depends on the given dictionary and the selected UUID length.

Out of the box this library provides a shuffled dictionary of digits from 0 to 9, as well as the alphabet from a to z both in UPPER and lower case, with a default UUID length of 6. That gives you a total of 56,800,235,584 possible UUIDs.

So, given the previous values, the probability of generating a duplicate in 1,000,000 rounds is ~0.00000002, or about 1 in 50,000,000.

If you change the dictionary and/or the UUID length then we have provided the function collisionProbability() function to calculate the probability of hitting a duplicate in a given number of rounds (a collision) and the function uniqueness() which provides a score (from 0 to 1) to rate the "quality" of the combination of given dictionary and UUID length (the closer to 1, higher the uniqueness and thus better the quality).

To find out more about the math behind these functions please refer to the API Reference.

Acknowledgement and platform support

This repo and npm package started as a straight up manual transpilation to ES6 of the short-uid npm package by Ankit Kuwadekar.

image depicting over 12000 weekly npm downloads image depicting over 100000 weekly cdn hits

Since this package is now reporting 12k+ npm weekly downloads and 100k+ weekly cdn hits, we've gone ahead and re-written the whole of it in TypeScript and made sure to package dist modules compatible with Deno, Node.js and all major Browsers.


Clone this repo:

git clone

git clone

Tests run using:

yarn test


In order to publish the latest changes you must build the distribution files:

yarn build

Then commit all changes and run the release script:

yarn release


Yes, thank you! This plugin is community-driven, most of its features are from different authors. Please update the docs and tests and add your name to the package.json file.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

🚧 💻 📖 ⚠️
💻 👀


Copyright (c) 2018-2021 Short Unique ID Contributors.
Licensed under the Apache License 2.0.