2

As an example imagine I generate a UUID/GUID for an ID in a json file.

{
  "25d01302-2558-4c44-bf9d-385b1cc51377": ["somevalues"]
}

is it ok or generally frowned upon to do something like

{
  "25d01302-2558-4c44-bf9d-385b1cc51377": ["somevalue"],
  "25d013o3-2558-4c44-bf9d-385b1cc51377": ["someothervalue"]
}

the second being a manually edited uuid/guid

This is something I come across recently and I can't tell if this is something you should avoid (just to be safe) or it is something that doesn't really matter either way?

RyanCosans
  • 209
  • 1
  • 7

3 Answers3

12

This very detailed answer to a similar question on stack overflow explains why GUIDs aren't random, but are highly structured, statistically unique values. By manually modifying an existing value, you are now just creating a random value, and you've potentially damaged the uniqueness in the process and thus a collision with a newly created GUID is more likely.

And GUIDs are easy to create, so there is no need to manually edit them anyway. Depending on whether you are using Windows, Linux or a Mac, just alias one of these to create an easy way of generating new guids:

Powershell: New-Guid | Set-Clipboard

Linux: cat /proc/sys/kernel/random/uuid | xclip -sel clip

Mac: uuidgen | pbcopy (thanks to B.J. in their comment below for this one)

In all cases, this will generate a new GUID and save it to the clipboard for you.

David Arno
  • 38,972
  • 9
  • 88
  • 121
3

By modifying existing UUIDs, you risk conflicting with a UUID generator provided by your system.

Take the macos uuidgen command line tool mentioned above. A reasonable method that reduces the probability of having any conflict by increasing the probability of having many conflicts is generating one "truly" random UUID and then using UUIDs that are consecutive in some sense. Just as you do, actually. As long as the system can guarantee that it won't return the same UUID twice that's fine (generating the same UUID twice could happen if the system crashes just after generating a UUID, before recording that a new UUID was created, but after an application has persisted the UUID).

If by bad luck you modify your UUIDs in the same way, then you will have massive numbers of conflicts with other UUIDs generated by the system. Absolutely don't do it.

gnasher729
  • 42,090
  • 4
  • 59
  • 119
0

You shouldn't modify an existing UUID or GUID if you're manually adding a record to something. There are plenty of online id generators you can use to create a new uuid whenever you need like this one: https://carova.io/tools/uuid-generator

AWS recently began supporting ULID which are structured time based unique identifiers. I've found using ULIDs as a unique identifier in NoSQL databases like DynamoDB really useful because they automatically sort your data by time (ULID). There are also a lot of online ULID generators too: https://carova.io/tools/ulid-generator