CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Generating a unique ID as a string from a GUID

223 Views
Copy Code Show/Hide Line Numbers
List<long> list = new List<long>();
 
byte[] bytes = Guid.NewGuid().ToByteArray();
long val = BitConverter.ToInt64(bytes,0);
 
val.Dump();
val.ToString("x").Dump();
val.ToString("x").Length.Dump();
 
for(int i=0; i<1000000; i++) {
    bytes = Guid.NewGuid().ToByteArray();
    list.Add((long) BitConverter.ToInt64(bytes,0));    
}                
 
list.Distinct().Count().Dump();
by Rick Strahl
  July 09, 2009 @ 1:21pm
Tags:
Description:
Generating a unique ID from a string. Better yet - encode with Base36 to reduce string to 12/13 chars.

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate