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.
1 2 3 4 5 6 7 8 9 | 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);
