This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

crc32 and VMID for unique names

 
Stephanie Smith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to generate unique names.
The VMID object is unique within a jvm.
I create the VMID, and then pass the bytes into CRC32 and convert to hex string.

Should this generated hex string be unique within like 100,000 iterations of creating a name? how likely are duplicates?
I have tested it with over 700K iterations (of creating VMID, passing into CRC32 and converting to hex string) with no duplicates but wanted to know if duplicates were possible.

Thanks for any advice.
 
Ladislav Honsa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

What do you want to use the unique names for? How many unique names do you need to generate?
I would probably use the java.util.UUID class instead. An UUID is 128 bit (i.e. 10^38) long. Of course, you can get duplicates. However it is VERY unlikely. See this link:
http://en.wikipedia.org/wiki/UUID#Random_UUID_probability_of_duplicates

Ladislav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic