Cutdown uuid next to make a short string

I need to create a unique record identifier for this unique string.

I tried using uuid format which seems good.

But we feel this is lasting.

so we need to shorten the string uuid 9f218a38-12cd-5942-b877-80adc0589315 to a smaller one. By removing the '-', we can save 4 characters. What is the safest part to remove from uuid? We do not need a universal unique identifier, but we like to use uuid as a source, but cut out strings.

We need a unique identifier specific to the site / database (SQL Server / ADO.NET Data Services).

Any idea or sample from any language is good.

Thanks in advance

+6
python string c # uuid uniqueidentifier
source share
5 answers

Why not just convert it to a base 64 string instead? You can shorten to 22 characters.

Saving UUID as base64 string

+8
source share

If you are using MS-SQL, you probably should just use the uniqueindentifier data type, it is compact (16 bytes), and since the SQL engine knows this, it can optimize indexes and queries using it.

+3
source share

The UUID provides (almost) 128 bits of uniqueness. You can shorten it to 16 binary bytes or 22 characters with base64 encoding. I would not recommend deleting any part of the UUID, otherwise it just makes no sense. UUIDs have been designed so that all 128 bits make sense. If you want less than this, you should use a different scheme.

For example, if you can guarantee that only UUIDs of version 4 are used, you can take only the first 32 bits or only the last 32 bits. You lose uniqueness, but you have pretty random numbers. Just avoid the bit that is fixed (version and version).

But if you cannot guarantee this, you will have real problems. For UUID version 1, the first bits will not be unique to UUIDs generated on the same day, and the last bits will not be unique to UUIDs generated on the same system. Even if you are a CRC UUID, it is not guaranteed that you will have 16 or 32 bits of uniqueness.

In this case, just use a different scheme. Create a 32-bit random number using the system random number generator and use this as your unique identifier. Do not rely on the UUID if you intend to remove its length.

+2
source share

UUID - 128 bits or 16 bytes. Without encoding, you can get this up to 16 bytes. UUIDs are usually written in hexadecimal, making them 32 byte readable strings. With other encodings you get different results:

  • base-64 converts 3 8-bit bytes into 4 6-bit characters, so 16 data bytes become 22 characters.
  • base-85 converts 4 8-bit bytes into 5 6.4-bit characters, so 16 bytes of data become 20 characters.

It all depends on whether you want to read the lines and how the standard / general encoding you want to use is.

+2
source share

UUID has 128 bits. Have you considered doing CRC? This can easily bring to 16 or 32 bits and use all the original information. If CRC is not good enough, you can always use the first few bytes of the correct hash (e.g. SHA256).

If you really want to simply shorten the UUID, its format is described in RFC 4122 . You should be able to figure out which parts your implementation does not need.

0
source share

All Articles