unique id

  • Thread starter Thread starter cj
  • Start date Start date
C

cj

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)

or

Dim uid as string = Now().Ticks.ToString.PadLeft(20, "0")
 
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/library/system.guid.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 :-)
 
Correct.

I've discussed it here and since we've been using the first 20 of guid
I'm going to continue with that bad tradition. I can't count on ticks
to be unique either after all and I need max 20 and I don't feel like
working with another component like ASCII85.

Thanks for you help.
 
Correct.

I've discussed it here and since we've been using the first 20 of guid
I'm going to continue with that bad tradition. I can't count on ticks
to be unique either after all and I need max 20 and I don't feel like
working with another component like ASCII85.

You shoudl just an incrementing counter ;-)
 
I've discussed it here and since we've been using the first 20 of guid
I'm going to continue with that bad tradition. I can't count on ticks
to be unique either after all and I need max 20 and I don't feel like
working with another component like ASCII85.

You can't count on the first 20 characters of a guid to be unique
either. Why can't you use the entire guid? That you can count on to
be unique.
 
Field I'm putting it in is 20 chars.

Like I said however if they've been getting by with the first 20 chars
in the past I'll just continue the bad practice.
 
Back
Top