Reputation: 511
I have read that randomness and uniform distribution are quite important for a hash function. How do I make a comparison between the randomness property of two different hash functions?
Upvotes: 0
Views: 2539
Reputation: 15693
Take two test strings that only differ very slightly, ideally by just one bit: BBBBBB
, BBBBBC
. Take the hash of each string with a hash function, and see how many bits of the output are changed by a one bit change in the input. An ideally random hash function should switch half the bits in the second output: changing one bit in the input changes half the bits in the output. Cryptographic hash function try to approach this ideal, while other hash function go some way towards it, but sacrifice ideal behaviour for speed.
Repeat for many pairs of almost identical strings to get an average measure of how random the first hash function is. Repeat for the second hash function. The one which gets closest to 50% of the bits changed on average is probably the more random hash function.
This test does not look at other criteria like speed.
Upvotes: 1