GUIDs are unique, but are they unique enough? There is, of course, a slim chance of a collision. Sure, you're more likely to be struck by a meteor and lighting while winning the lottery on a Tuesday during Lent while driving your Ferrari to the diner for pancakes, but it can happen!

Who wants to live in a world with that kind of risk? Sergei sent us this code, and whoever wrote it sounds like a very careful kind of person.

private Guid DifferentGuid(params Guid[] guids)
   Guid result = Guid.NewGuid();

   while (guids.Any(g => g == result))
       result = Guid.NewGuid();

   return result;

Here is how it's used:
Guid guid1 = Guid.NewGuid(); Guid guid2 = DifferentGuid(guid1); Guid guid3 = DifferentGuid(guid1, guid2);

The deadline to snag one of TDWTF's snazzy T-Shirts is coming soon! Deploy New Relic's real-time analytics software by August 15th and one will be headed your way.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!