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.
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);
I use following:
now.ticks + random number.
Maybe you try to calculate with the MAC Adress.
Joerg
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.