Tuesday, 12 November 2024

How to Generate a GUID/UUID in JavaScript: Modern Solutions for Unique Identifiers

 GUIDs (Globally Unique Identifiers), also called UUIDs (Universally Unique Identifiers), are a standard way to generate unique identifiers in software applications. In JavaScript, you can generate GUIDs to uniquely identify objects, store them in databases, or share them across different systems.

This post will explore methods for generating UUIDs, focusing on various approaches, especially ones that don’t rely on Math.random() due to its limitations in randomness and uniqueness.

What is a GUID/UUID?

A UUID is a 128-bit identifier formatted as "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx", where:

  • x represents a hexadecimal digit (0-9, a-f).
  • M indicates the UUID version (e.g., 4 for randomly generated UUIDs).
  • N is a variant, usually one of 8, 9, a, or b.

Read more »

Labels: