google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.24k stars 363 forks source link

UUID with repeat ending #108

Closed pedroalbanese closed 1 year ago

pedroalbanese commented 1 year ago

Greetings!

I would like to know why version 1 repeats the ends of sequences, ie using NewUUID() the results always end in -0022684e5e1b. Is there a way to change this or a purpose for this to occur?

Thanks in advance.

tkarrass commented 1 year ago

Hi pedroalbanese!

This is by design of version 1 UUIDs. The last six octets are the node id, which is the mac address of the host generating the UUID in this case. Have a look at https://www.rfc-editor.org/rfc/rfc4122#section-4.1.2 for details about the format. If you want to create randomly generated UUIDs you should use the New() func instead of NewUUID(), which returns a version 4 UUID. Also, this module allows you to set the node id to a custom value using SetNodeId() if you like. However, you should read section 4.5 of the RFC to learn about the caveats and how to avoid collisions.

Best regards!

pedroalbanese commented 1 year ago

Thank you very much!