# “Unique” number from several values

I'm trying to create a unique unsigned "long" number (64 bits) from a list of 4 other numerical values. Some function f(n1, n2, n3, n4) = x. The order of the values is important so unfortunately I can't use this technique (calculating unique value from given numbers) which seems to give the same unique value from a set of numbers where order doesn't matter.

For example n1 = 10, n2 = 14, n3 = 18, n4 = 21 should be different than m1 = 10, m2 = 1, m3 = 418, m4 = 19. In addition, o1 = 10, o2 = 14, o3 = 21, o4 = 18 should also be different.

I realize it might not be possible to get a truly unique number due to the 64-bit limitation but if you can help me to find a number that's very unlikely to be unique, that would be very very nice:)

Other interesting suggestions that I've looked at:

Function for unique hash code

Deduce a unique number from number

Calculate unique Integer representing a pair of integers

Perhaps that last one could be applied three times? Since 4 values are two pairs, each pair could generate a unique value and then the two unique values could be used in the function again?

• Thanks for your input and I realise designing hash functions for security reasons is a bad idea. I didn't realise Java's hashCode() actually returns an int. Thanks. hashCode() -> s*31^(n-1) + s*31^(n-2) + ... + s[n-1]. Since I'm in c++ I guess I'll build a string and use this: std::hash<std::string>()("foo");. Funny how googling can be this random after searching for 1 hour without results :P – span Feb 11 '14 at 15:49