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?

6
  • 4
    This likely answers your question: stackoverflow.com/a/10892448/7122. TLDR: it's better to generate new ones.
    – David Arno
    Nov 24 at 10:46
  • 16
    You should 100% definitely avoid doing what you've done because o is not a hex digit. Nov 24 at 10:48
  • 1
    makes it 110% unique though :)
    – Ewan
    Nov 24 at 11:04
  • 1
    How can you guaranty it's global or universal uniqueness if your changes are so predictable? Nov 24 at 12:30
  • Are you using variant 1 or variant 2? Are you using version 1, 2, 3, 4, or 5? Nov 24 at 14:00
9

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.

1
  • 3
    On macOS: the shell command line is: uuidgen | pbcopy
    – B.J.
    Nov 24 at 11:36
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.