title: Uniform distribution in a hash function
body: <p>I've written the following basic hash function for playing around with a hashmap data structure:</p>
  <pre><code>static int ht_hash(const char* s, int prime, int num_buckets)
  {
      long hash = 0;
      size_t len_s = strlen(s);
      for (int i=0; i &lt; len_s; i++)
      {
          // 1. left-most digit should be prime^^len-1, right-most should be prime^^0
          long prime_to_power = (long) pow(prime, len_s - (i+1));
          // 2. multiple that value for the digit times the code (asci code in this case) for that char
          hash += prime_to_power * s[i];
      }
      // 3. hash / modulo
      hash %= num_buckets;
      return (int) hash;
  
  }
  </code></pre>
  <p>How can one determine a 'good' bucket size or 'prime' for a basic hashing function such as the above? I understand that the goal is to have a uniform distribution. But is there a way to do this other than, for example, to do a brute-force with 100k values, for example:</p>
  <pre><code>for (int num_buckets=0; num_buckets &lt; 100000; num_buckets++)
      // for (int prime=1; prime &lt; 10000; prime=get_next_prime())
      // or, if we want to grab all numbers, not just prime and see for ourselves
      for (int number=1; number &lt; 100000; number++)
  
          // ... store some histogram-like data
  </code></pre>
  <p>Or, is this more an abstract mathematical area where there are proofs showing possible conditions/constraints for a uniform distribution? In other words, what might be a good way to learn more about hashing functions and how they are done? and how they are confirmed to be uniform?</p>