I am trying to come up with a good hash function for a string and an integer that will just return a positive integer. I was thinking about taking the sum of the Unicode characters of the string and multiplying it with the integer, and then taking the absolute value of that. Would you say that is a good hash function? Will that give an even distribution? And do you have any ideas about how to test this with random or something like that?
This is what my class looks like now:
class MyHashableKey:
def __init__(self,int_value,string_value):
self.int_value=int_value
self.string_value=string_value
def __hash__(self):
str_value = sum([ord(x) for x in self.string_value])
my_hash = abs(str_value * self.int_value)
return my_hash