I understand that UUID is generated based on bits given by timestamp.

For instance, if two iOS devices at the exact same time executes the following statement then what possibility is there that it will generate same uuid?

let uuid = NSUUID().uuidString

If uuid is combination of more than just timestamp, what is the internal logic using which UUID is generated?

  • Are you talking about version 1, 2, 3, 4, or 5 UUIDs? – Jörg W Mittag Oct 31 '18 at 15:38
  • 1
    Generally it uses some random entropy already existing in the system plus the current time. So whatever internal process is used for RNG in the system library, it includes the timestamp, it’s not only the timestamp. It’s basically system entropy + timestamp = RNG seed. I don’t know what the entropy factors are in iOS though. And each system (iOS device) would have its own unique system entropy. UUID are called so for a reason, after all. – Chris Cirefice Oct 31 '18 at 15:39
  • 1
    @JörgWMittag I think swift uses version 4 – kamalpreet Oct 31 '18 at 15:42
  • Universally Unique ID – Ewan Oct 31 '18 at 22:04
  • 1
    The RFC does not specify what the random source is. It does warn however that not every implementation may be capable of generating that many bits of entropy. AFAIK, newer iOS devices have hardware-based entropy sources. – Jörg W Mittag Oct 31 '18 at 22:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.