I need to create unique numerical ids for some short strings.
some.domain.com -> 32423421
another.domain.com -> 23332423
yet.another.com -> 12131232
Is there a Perl CPAN module that will do something like this?
I've tried using Digest::MD5 but the resulting numbers are too long:
some.domain.com -> 296800572457176150356613937260800159845
Just take the first 8 digits of the MD5 hash. This works because MD5 is uniformly distributed over its hash address space. This means that any consecutive sequence of MD5 hash digits will itself be a uniformly distributed hash.
Alternatively, just use some other uniformly-distributed hashing mechanism that returns 8 numbers. Whatever's easiest for you.
Either Digest::CRC or String::CRC32. The first gives you option to calculate 8-, 16- and 32-bit chcecksums, while second only supports 32-bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With