-2

I have a scenario where i need to generate a unique key for which i am using Guid.NewGuid() in C#, and sending this key to the user via an email when user request for it and for next 48Hrs that user will be identified by this unique key. There is no limit for the user to request for this key but only the latest one will be a valid key to identify the user. My question is when C# reached the limit to generate new key what happens then?. Do i really need to worry about it?

  • *"My question is when C# reached the limit to generate new key what happens then?"* -- do you mean what happens if C# runs out of possible GUIDs? – canton7 Jun 01 '20 at 10:10
  • 3
    Eric Lippert's [Guid guide, part three](https://ericlippert.com/2012/05/07/guid-guide-part-three/): "There are on the order 2³⁰ personal computers in the world (and of course lots of hand-held devices or non-PC computing devices that have more or less the same levels of computing power, but lets ignore those). Let’s assume that we put all those PCs in the world to the task of generating GUIDs; if each one can generate, say, 2²⁰ GUIDs per second ... the odds of collision get pretty good after only thirty trillion years." – Damien_The_Unbeliever Jun 01 '20 at 10:12
  • 2
    Does this answer your question? [Is a GUID unique 100% of the time?](https://stackoverflow.com/questions/39771/is-a-guid-unique-100-of-the-time) – Iam_NSA Jun 01 '20 at 10:15
  • I think [this](https://stackoverflow.com/a/1705604/2501279) would be an interesting answer to read. – Guru Stron Jun 01 '20 at 10:16
  • https://en.wikipedia.org/wiki/Universally_unique_identifier (have a look at *collisions* chapter) – Dmitry Bychenko Jun 01 '20 at 10:24
  • @canton7 Yes exactly. – sowmya.saguturu Jun 01 '20 at 11:50

1 Answers1

2

I'll quote this page from the Online Guid Generator

128-bits is big enough and the generation algorithm is unique enough that if 1,000,000,000 GUIDs per second were generated for 1 year the probability of a duplicate would be only 50%. Or if every human on Earth generated 600,000,000 GUIDs there would only be a 50% probability of a duplicate.

You will never need to worry about it.

Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205