in reply to Short hash algorithm

If you are not worried about security or collision frequency, you could use a mod:
my $short = $digest % ($largest_int_wanted + 1);
Alternately, you could use the 5-6 least significant characters of the digest.

-Mark

Replies are listed 'Best First'.
Re^2: Short hash algorithm
by Corion (Patriarch) on Nov 18, 2004 at 07:39 UTC

    Taking the modulus doesn't prevent people from guessing the next and/or previous key, as it will likely still be n+1 or n-1, if the modulus is large enough. But based on the modulus idea, one could use the linear method used by random number generators - take a large prime number, multiply the record number by it, and then take the modulus - this should give a fairly good distribution, but I'd still look at what Knuth (or some other book) says about the algorithm. I think it's called Linear Random Number Generator, but it might be called something else.