1

I know perfectly well that Guids are supposed to be globally unique. This is a special case.

We have tools that create configuration files where Guids are part of the data. Creating new Guids every time you run the tool is very easy. However, in a couple of test scenarios, we are faced with the problem that independent tools should create objects with the same Guid where some underlying data match. To maintain and access a centralized repository of Guids in use is not practical.

By "seeding", I mean that having two different seeds is guaranteed to produce different Guids and that the same seed will always produce the same Guid.

Tormod
  • 4,551
  • 2
  • 28
  • 50
  • It doesn't seem to be the same as HashCode. Two completely different objects might (in fact, often do) return identical hashcodes. It appears that you'd like to guarantee different Guids for different objects. But how do you define the seed ? If same seeds -> same Guid and different seeds -> different Guid, why not use the seed as the discriminant you're looking for ? – xlecoustillier Jun 28 '13 at 10:17
  • Well, that's what I'm doing. I'm using the seed as the (real) discriminant, but only in the test data produced by the tooling. The system that we're testing demands that the Guid must be the same in order for it to work. This is to produce consistent test data from a distributed set of tools. – Tormod Jun 28 '13 at 10:22
  • The current solution I'm looking at is to create and distribute a single guid and hardcode it into every tool and then, every time a Guid is needed, a new guid is achieved by replacing a specific part of it with the hash code. Then name equality in two separate tools will result in them independently producing the same Guid. I don't like the solution, but it may help you understand what I'm trying to achieve. – Tormod Jun 28 '13 at 10:27
  • 1
    This is technically possible, but not supported by System.Guid. The fine details are in RFC-4122, section 4.3, "Algorithm for Creating a Name-Based UUID". You now know the proper google query, "c# name based uuid" produces: – Hans Passant Jun 28 '13 at 10:51
  • And don't use GetHashCode(), you need a better hash. SHA-1 is good. – Hans Passant Jun 28 '13 at 10:56

0 Answers0