Generate a unique numeric ID based on the string. Generally, GUID is used. MD5 is calculated based on the string. The calculated MD5 code is a guid.
However, The GUID is too long. It is a 128-bit number. during storage, it takes a lot of space and determines whether to generate a shorter number, such as a 32-bit number, someone has provided this method.
: We can set a standard guid21726045-e8f7-4b09-abd8-4bcc926e9e28Convert to a short string3c4ebc5f5f2c4edc
The following method generates a short string that is unique. Repeat is not repeated for 0.1 billion times. It also generates the string according to the guid uniqueness.
Private String Generatestringid ()
{
Long I = 1 ;
Foreach ( Byte B In Guid. newguid (). tobytearray ())
{
I * = (( Int ) B + 1 );
}
Return String . Format ( " {0: x} " , I - Datetime. Now. ticks );
}
If you want to generate a numerical sequence instead of a string, you will get a 19-bit long sequence. The following method converts a guid to an int64 numeric sequence.
Private Long Generateintid ()
{
Byte [] Buffer = Guid. newguid (). tobytearray ();
Return Bitconverter. toint64 (buffer, 0 );
}
it seems that this method is feasible, but no rigorous data demonstration is found for the time being to ensure high non-conflict performance. after all, the key value is used. If there is a duplicate value, the Program will be suspended.