Short UUID Generator

Provide the length of the UUID
Provide the number of IDs

 

Short Unique ID (Short UUID)

Generate short, unique, and easy-to-read UUIDs for your applications

Table of Contents

Introduction

The Short Unique ID library is a powerful tool for generating short and unique identifiers (UUIDs) for your applications. It offers a simple yet efficient solution to handle identification requirements without relying on lengthy and complex UUID strings.

Installation

Before you can start using the Short Unique ID library, you need to install it in your Node.js project. To do so, follow these steps:

$ npm install short-unique-id

Usage

Once you have installed the library, you can import it into your JavaScript code using the following line:

const { ShortUniqueId } = require('short-unique-id');

The Short Unique ID library provides various methods to generate unique IDs based on your requirements. Some of the commonly used methods are:

Example

Let's see a simple example of how to generate a short unique ID using the Short Unique ID library:

const { ShortUniqueId } = require('short-unique-id');

const uid = new ShortUniqueId();
const id = uid.generate();

console.log(id); // Output: "2jt34n"

Conclusion

The Short Unique ID library provides a convenient and efficient way to generate short and unique identifiers for your applications. By using this library, you can simplify the handling of identification requirements and improve the readability of your UUIDs. Whether you need to generate unique IDs for user records, database entries, or any other purpose, the Short Unique ID library offers a reliable solution.

What is the likelihood of generating an identical ID again?

This probability is largely contingent on the specified dictionary and the chosen length of the UUID.

By default, this library furnishes a randomized dictionary comprising digits from 0 to 9 and both uppercase and lowercase letters from 'a' to 'z', with a standard UUID length of 6. This configuration yields a grand total of 56,800,235,584 potential UUIDs.

Given these parameters, the probability of generating a duplicate in 1,000,000 rounds is approximately 0.00000002, or roughly 1 in 50,000,000.

Should you opt to modify the dictionary and/or alter the UUID length, we've equipped the library with the collisionProbability() function. This function calculates the likelihood of encountering a duplicate within a specified number of rounds (a collision). Additionally, the uniqueness() function is at your disposal, offering a score between 0 and 1 to assess the "quality" of the chosen combination of dictionary and UUID length. The closer the score is to 1, the higher the uniqueness, signifying better overall quality.