[Math] Is the product of 2 unique prime number unique

algorithmshash functionprime numbers

I am wondering if I take the product of 2 unique prime numbers, and will the product be unique ? any chance to have collision ? I mean will any other 2 unique prime numbers have the same product ? because I want to see if I can use that product as a key in the hash table as well as use it as an (unique) ID.

Best Answer

Are you familiar with the Fundamental Theorem of Arithmetic (so, by the FTA, this number would be unique, but maybe this is not sufficient for your application - read on)?

http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic

Additionally, how many unique IDs do you need?

Have you considered how large of prime numbers you will need to represent that?

Maybe you want to use a product_id || serial_number || date & time-stamp or some mixing like that to guarantee a unique ID.

You can also consider using the new SHA-3 (Keccak) at: http://en.wikipedia.org/wiki/SHA-3 . You can take a large hash value and truncate it (but there is the possibility of collisions), so you can prepend the items above to avoid those.

Also, maybe something like this is what you are after: http://www.javapractices.com/topic/TopicAction.do?Id=56 .

RFC 4122: A Universally Unique IDentifier (UUID), covers this sort of thing and you might want to read it because this is likely what you are after (a secure way to generate a universally unique ID).

For security reasons, Unique identifiers which are "published" in some way may need special treatment, since the identifier may need to be difficult to guess or forge.

Just wanted to throw out some additional thoughts for your consideration given some of the comments and feedback above.

Regards -A