I have the a function I took from this post which works great:
private string GenerateTransactionCode()
{
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var random = new Random();
var result = new string(
Enumerable.Repeat(chars, 8)
.Select(s => s[random.Next(s.Length)])
.ToArray());
return result;
}
I would like to modify it so that instead of it being random, it picks the alpha numeric digits based on DateTime.UtcNow.Ticks. This way it will be non-repeating. I suppose the characters in the resulting TransactionCode might need to be increased depending on the length of the milliseconds? I would like the length of the resulting TransactionCode to be constant. Hopefully, no more than 8 Characters.
Example: If the ticks happened to be 135 (going to me more than that in real life) then the resulting code will be ACE or BDF depending if it’s 0 based (I don’t care if it is or not).
I imagine what you actually want is a real non-repeating transaction code, or GUID:
If you want to clean it up:
Example of generated output is
OEndimZwsEKRAbAwnvzjoAbut because of the replacement of+/and=the length can be slightly unpredictable.You may prefer this format
g.ToString("N")which gives something like58d5381c878b484591568b086296fe8eand is guaranteed to be 32 characters long.