March 27, 2021
2 mins read

How to create a GUID / UUID

What Is A UUID And How To Generate One?

A UUID or Universally Unique Identifier is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen (“-“, U+002D). This means that there is a one in two billion chance of having the same UUID as somebody else. It can be used for a variety of purposes, from generating ids for databases, to creating unique ids for website registrations, to providing unique identifiers for printers on your home network.

What is a UUID and GUID?

A UUID is a unique identifier that’s stored as a string of hexadecimal digits and four uppercase letters. They are used for many purposes such as identifying users, groups, companies and much more. A GUID is simply another term for a UUID.

Tips for Generating Uniqueness For Your Unique ID

A GUID is an acronym for global unique identifier. A GUID is a type of UUID that can be generated by using a variety of different methods. One way to create a GUID is to use Polypad; a scriptable textpad. Another method is to use an online tool or even your browser if you are in need of something very quickly.

A GUID or UUID should be in following format, xxxxxxxx-xxxx-Axxx-Bxxx-xxxxxxxxxxxx. The position at A will always be 4 and the position at B will be either 8,9,A,B where A and B are not case-sensitive. To learn more about the following format checkout version 4 UUID defined in RFC4122; a 128 randomly-generated bits with six bits at certain positions set to particular values. For example,

How to Create a UUID

Creating a UUID is insanely easy with Polypad by building a reusable script. You can either use the code below in your browser or create a script using Polypad to perform the text transformation.

function generate_uuid() {
   return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
      return v.toString(16);
   });
}

function main(input) {
    input.text = generate_uuid();
}

Tips for Generating Uniqueness For Your Unique ID

If you need a unique ID for your database, or for your own personal use you can quickly generate one using the code snippet above.