1
$\begingroup$

if I take the result of a 32bit hash function(the param is random string) and apply module N on the result - will the values be evenly distributed?

so if I have a histogram of values [0,N-1] will the histogram be evenly distributed ?

Thanks

$\endgroup$

1 Answer 1

4
$\begingroup$

if I take the result of a 32bit hash function(the param is random string) and apply module N on the result - will the values be evenly distributed?

It depends on the hash function. For a good hash function the output should be uniformly distributed.

so if I have a histogram of values [0,N-1] will the histogram be evenly distributed ?

For any reasonable hash function, yes.

Keep in mind that real-world hash functions are sometimes terrible. Many programming languages will, as the hash of an integer (using the built-in hashing function), return the original value. This is not a problem if your input is truly random, but usually the reason to use a hash function is to take an input that has some structure, and produce hashes that (hopefully) don't.

$\endgroup$
1
  • $\begingroup$ I edited my post - I didnt meant to say that its 'exactly' 10 values of each but 'more or less'.. so just to verify your answer - if the hash function is uniformly distributed so applying modulo on the result will still be uniformly distributed? $\endgroup$
    – nadavgam
    Commented May 4, 2019 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.