Hi Fellow Statisticians,
I have a source generating hashes (e.g. computing a string with a timestamp and other information and hashing with md5) and I want to project it into a fixed number of buckets (say 100).
sample hash: 0fb916f0b174c66fd35ef078d861a367
What I thought at first was to use only the first character of the hash to choose a bucket, but this leads to a wildly non-uniform projection (i.e. some letters apppear very rarely and other very frequently)
Then, I tried to convert this hexa string into an integer using the sum of the char values, then take the modulo to choose a bucket:
import sys for line in sys.stdin: i = 0 for c in line: i += ord(c) print i%100
It seems to work in practice, but I don't know if there are any common sense or theoretical results that could explain why and to which extent this is true ?
[Edit] After some thought I came to the following conclusion: In theory you can convert the hash into a (very big) integer by interpreting it as a number : i = h + 16*h+16*16*h ... + 16^31*h (each letter represents an hexadecimal number). Then you could modulo this big number to project it to the bucket space. [/Edit]