cj <cj@nospam.nospamwrote in news:u3XY4nBiHHA.1388
@TK2MSFTNGP05.phx.gbl:
I need to choose a 20 char unique id for transactions handled by my
multithreaded program. I can't decide if to use
Dim uid As String = Guid.NewGuid.ToString
uid = uid.Replace("-", "")
uid = uid.Substring(0, 20)
You don't need to do the replace line - the .ToString command has
different formatters:
http://msdn2.microsoft.com/en-us/lib....tostring.aspx
and in particular:
http://msdn2.microsoft.com/en-us/library/97af8hh4.aspx
Guid.NewGuid.ToString("N") will return an all numeric value.
Also you can't take a substring of a GUID and expect it to be unique...
A GUID is only unique if all 32 digits are present.
>
or
Dim uid as string = Now().Ticks.ToString.PadLeft(20, "0")
While the resolution of ticks is quite good, I'm not sure this can
gaurantee uniqueness as well. It really depends on how many concurrent
requests you're planning on handling.
Take a look at this:
http://www.codinghorror.com/blog/archives/000409.html
Shows you how to convert a 16byte GUID into a 20 byte ASCII
representation :-)