This is a homework question
I am attempting to write a hash function that will evenly distribute 20 randomly selected census name into 20 buckets. I may have up to three collisions of two each.
public int hashCode(Contact c) {
// TODO Auto-generated method stub
int result = 0;
for(char d: c.getFirstName().toCharArray()) {
result += d % 26;
}
result *= c.getFirstName().charAt(0) / c.getLastName().charAt(0) % 26;
for(char d: c.getLastName().toCharArray()) {
result += d % 26;
}
result *= c.getFirstName().length();
result /= c.getLastName().length();
//result *= c.getLastName().charAt(c.getLastName().length() / 2) % 26;
return result % 20;
}
This code is a bit random and when ran produces a bell curve. I understand the English language is a bit biased towards vowels and certain characters. Any ideas on how to more evenly distribute the names.