def string_hash(text, mod):
    """ Return a hash value for an ASCII string. The value will be
    between 0 and mod-1. It is advisable to use a prime number
    for mod to guarantee a fairly uniform distribution. """
    base = 256 # size of the alphabet (ASCII)
    numstr = [ord(char) for char in text]
    length = len(numstr)
    hashval = 0
    assert all(0 <= num < base for num in numstr)
    for ind, val in enumerate(numstr):
        hashval += base ** (length-ind-1)*val
        hashval %= mod
    return hashval