Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating 8-character only UUIDs

Tags:

java

uuid

UUID libraries generate 32-character UUIDs.

I want to generate 8-character only UUIDs, is it possible?

like image 591
M.J. Avatar asked Nov 24 '10 13:11

M.J.


People also ask

How many UUIDs can be generated?

32 hexadecimals x log2(16) bits/hexadecimal = 128 bits in a UUID. In the version 4, variant 1 type of UUID, 6 bits are fixed and the remaining 122 bits are randomly generated, for a total of 2¹²² possible UUIDs.

How many characters are UUIDs?

Universally Unique Identifiers, or UUIDS, are 128 bit numbers, composed of 16 octets and represented as 32 base-16 characters, that can be used to identify information across a computer system.

How do I reduce my UUID size?

You can use base64 encoding and reduce it to 22 characters. If you use base94 you can get it does to 20 characters. If you use the whole range of valid chars fro \u0000 to \ufffd you can reduce it to just 9 characters or 17 bytes. If you don't care about Strings you can use 16, 8-bit bytes.

How are UUIDs generated?

UUID was standardized by the Open Software Foundation (OSF), becoming a part of the Distributed Computing Environment (DCE). Different versions of UUID follow the RFC 4122 specification. UUIDs are generated using an algorithm based on a timestamp and other factors such as the network address.


1 Answers

It is not possible since a UUID is a 16-byte number per definition. But of course, you can generate 8-character long unique strings (see the other answers).

Also be careful with generating longer UUIDs and substring-ing them, since some parts of the ID may contain fixed bytes (e.g. this is the case with MAC, DCE and MD5 UUIDs).

like image 73
Cephalopod Avatar answered Oct 01 '22 19:10

Cephalopod