Unique Number like GUID

  • Thread starter Thread starter David Pope
  • Start date Start date
D

David Pope

I need to create a unique number like a GUID but all numbers.

Does anyone know of algorithm to do this?

Thanks,

David
 
Hello,

I'm using a call like this one:

GuidKey = System.Guid.NewGuid().ToString("N");

Yo ucan select the 'format' you want.


L.M
 
Unique in what context? Unique at the transaction level, table level or
globally (outside the server)?

There are several options, but if this data is to inserted into a table,
then you will want to consider the storage requirements of the values. A
GUID (ex: 6F9619FF-8B86-D011-B42D-00C04FC964FF) is 32 bytes in alpha-numeric
format and would still require a (8 byte) Big Int if converted to numeric.
If you just need a unique numeric value inserted into a table column, then
an auto incremented integer would be the logical choice.
 
Hi David,

I don't know your context, so I don't know whether this method is the best.

So, in addition to the others, let me also suggest using the
RNGCryptoServiceProvider class (in the System.Security.Cryptography
namespace), which derives from the RandomNumberGenerator class.
Eg: (in the context of creating a salt)

byte[] saltInBytes = new byte[8];
RNGCryptoServiceProvider saltGenerator = new RNGCryptoServiceProvider();
saltGenerator.GetBytes(saltInBytes);
string saltAsString = Convert.ToBase64String(saltInBytes);

HTH,
Rakesh Rajan
 
if it is not that frequent how aboout using the current date & time

e.g.

DateTime.Now.Ticks

HTH

Ollie Riches
 
I agree with you.
this is a good way.

I use following:
now.ticks + random number.
Maybe you try to calculate with the MAC Adress.

Joerg
 
Back
Top