I found it extremely amusing to read the confused comments and answers from our cybernetic friends -- who genuinely didn't get the question, because it was written using vague, human being wording.
Now having said that, it is perfectly valid to advocate for hard-coding the Guid. Guids should be random, by definition I will just answer the question technically, without questioning its underlying choice.
What @w0051977 wanted (paraphrased)
Guid g = MySeededGuidGenerator.CreateGuid(); // Generates the same sequences of Guids each time the program runs
Implementation
public static class MySeededGuidGenerator {
private static int sequence;
public static Guid CreateGuid() {
using (MD5 md5 = MD5.Create()) {
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes($"{sequence++}"));
return new Guid(hash);
}
}
}
Note: You might get warnings that md5.ComputeHash is unsafe cryptography, but here we use it as a cheap way of generating a Guid from a string, not in any security-oriented way. Therefore it doesn't matter, because it is accepted that anyone who would want a program where the Guids are not randomized (but instead always the same) has no concern for security. My guess is that it's just for mass-seeding a test environment in a deterministic manner.
Output :
(start program)
var guid1 = MySeededGuidGenerator.CreateGuid();
var guid2 = MySeededGuidGenerator.CreateGuid();
var guid3 = MySeededGuidGenerator.CreateGuid();
(stop program)
(run program again)
var guid1 = MySeededGuidGenerator.CreateGuid();
var guid2 = MySeededGuidGenerator.CreateGuid();
var guid3 = MySeededGuidGenerator.CreateGuid();
Success! The values of guid1, guid2 and guid3 were identical (respectively) the second time to the first time.