The division method is one way to create hash functions. The functions take the form:
h(k) = k mod m
Where k is a key and m is the number of slots
Edit: If this is my hash function why should I choose m to be prime ? I understand the problem that if I choose m to be a power of 2 i.e m = 2^p, then the h(k) only looks at the p lower bits of k, completely ignoring the rest of the bits in k. Why not choose a odd composite number ?
I have seen this answer https://stackoverflow.com/questions/3613102/why-use-a-prime-number-in-hashcode/3613423#3613423 but it kinds of explain the problems that we face if all the keys are of the form 4^p but doesn't quite explain why choose a prime but not a composite odd ? I also checked out https://stackoverflow.com/questions/5152015/why-setting-hashtables-length-to-a-prime-number-is-a-good-practice but then also I am not clear on it .