Int(11) to Fixed num (8 charactors) uniq hash?

If you simply need a hash function for hash table lookup, I recommend using Murmurhash 10^11 is between 2^36 and 2^37. Therefore, call a hash that generate 64-bit (Murmurhash2) or 128-bit (Murmurhash3) hash, and mod 10^11. Unlike simply converting bases, using hash function may generate conflicts, even it is highly (if not perfectly) uniformly distributed.

However, you will get much better avalanche effect Here is its avalanche test result If Murmurhash is not possible, Jenkins lookup functions are also good Here is its avalanche test result If performance is not a problem, or it is required cryptographic secure, SHA-1 might be the best pick, which has much more wrappers in various languages. Do not use CRC32 (bad avalanche) EDIT : If you need PHP hash function, here is a sample code function my_hash($user_id, $order_type) { // construct integer (10^11) $data = $user_id * 10 + $order_type; // convert decimal to raw binary string (at most 5 bytes) $hex = dechex($data); $binary = pack('H*', $hex); // hash binary string. Substitute 'sha1' with other algorithms listed in http://www.php.net/manual/en/function.hash-algos.php if needed $hash = hash('sha1', $binary); // output first 8 bytes return substr($hash, 0, 8); } echo my_hash(1234567890, 0); // 199f4bc7 echo my_hash(1234567890, 1); // f3706f03 Also, there is PHP extension for Murmurhash2 You can compile and install if you run PHP on Linux.

Replace those Murmurhash2 files with Murmurhash3 might be even better.

If you simply need a hash function for hash table lookup, I recommend using Murmurhash. 10^11 is between 2^36 and 2^37. Therefore, call a hash that generate 64-bit (Murmurhash2) or 128-bit (Murmurhash3) hash, and mod 10^11.

Unlike simply converting bases, using hash function may generate conflicts, even it is highly (if not perfectly) uniformly distributed. However, you will get much better avalanche effect. Here is its avalanche test result.

If Murmurhash is not possible, Jenkins lookup functions are also good. Here is its avalanche test result. If performance is not a problem, or it is required cryptographic secure, SHA-1 might be the best pick, which has much more wrappers in various languages.Do not use CRC32 (bad avalanche).

EDIT: If you need PHP hash function, here is a sample code function my_hash($user_id, $order_type) { // construct integer (10^11) $data = $user_id * 10 + $order_type; // convert decimal to raw binary string (at most 5 bytes) $hex = dechex($data); $binary = pack('H*', $hex); // hash binary string. Substitute 'sha1' with other algorithms listed in http://www.php.net/manual/en/function.hash-algos.php if needed $hash = hash('sha1', $binary); // output first 8 bytes return substr($hash, 0, 8); } echo my_hash(1234567890, 0); // 199f4bc7 echo my_hash(1234567890, 1); // f3706f03 Also, there is PHP extension for Murmurhash2. You can compile and install if you run PHP on Linux.

Replace those Murmurhash2 files with Murmurhash3 might be even better.

Thank's for great answer. I have to read. But I'm using php5 if you could same tool in php I'm so happy .

– freddiefujiwara Apr 27 at 1:09 It's is the code I wanted! Thank you so much. But my env php test.

Php 72307cb3 04cb0609 the hash code are changed by env(OS or .. ) – freddiefujiwara Apr 27 at 3:36 in my survay . The pack() funciton is broken on x86_64 – freddiefujiwara Apr 27 at 3:44 I use pack() simply to minimize the input of the hash function. You can skip the dechex and pack steps and directly pass (string) $data to hash().

Remember, there may be collisions. – Crend King Apr 27 at 4:53.

You can use a trivial hash function because: 36^8 = 2821109907456 10^12 - 1 = 999999999999 The range of 0-9a-z{8} is larger than 10^12 - 1. The trivial hash function would be to convert your number from base 10 to base 36 and left padd with 0 to the required length. As it was pointed out, this might not satisfy uniformity.

However for a hash function uniformity is usually required to minimize the cost of collisions which do not exist in this case. If that doesn't satisfy your requirements then you need to get more specific.

I agree that in this scenario the hash will not conflict. However, remember that there are two other properties for a good hash function: uniformly distributed and strictly avalanche. Simply converting bases will not satisfy these properties.

– Crend King Apr 27 at 0:38 Mh, good point. Updated my answer a bit. Depending on the purpose it might still be a valid approach.

– ChrisWue Apr 27 at 1:33.

If you simply need a hash function for hash table lookup, I recommend using Murmurhash. 10^11 is between 2^36 and 2^37. Therefore, call a hash that generate 64-bit (Murmurhash2) or 128-bit (Murmurhash3) hash, and mod 10^11.

Unlike simply converting bases, using hash function may generate conflicts, even it is highly (if not perfectly) uniformly distributed. However, you will get much better avalanche effect. Here is its avalanche test result.

If Murmurhash is not possible, Jenkins lookup functions are also good. Here is its avalanche test result. If performance is not a problem, or it is required cryptographic secure, SHA-1 might be the best pick, which has much more wrappers in various languages.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions