title: Is this the correct way of testing the avalanche effect of a hash function?
body: <p>I am trying to implement a hash table in C to enrich my understandings of data structures.</p>
  <p>There are a lot of hash functions out there for hash table implementations.</p>
  <p>To compare the hash functions, there is a test called the avalanche effect test.</p>
  <p>To test the set of hash functions I currently have, I wrote a small program in Java:</p>
  <pre><code>    public static void testHashAvalanche() {
          Set&lt;Long&gt; collisionSet = new HashSet&lt;&gt;();
          // The input for the hash function with 128 bytes.
          byte[] bytes = new byte[128];
          long count = 0;
          long previous = 0;
          long totalAvalanche = 0;
          // Generate the inputs for hashing with a slight change of bit each time
          for (int i = 0; i &lt; 128; i++) {
              // Byte value from 0 -&gt; 255
              for (int j = 0; j &lt; 256; j++) {
                  long current = hash(bytes); // Any hash function with 64 bit output
                  int avalanche = calculateAvalanche(previous, current);
                  totalAvalanche += avalanche;
                  bytes[i]++;
                  count++;
                  previous = current;
              }
          }
          System.out.println(&quot;Average Avalanche: &quot; + (double) totalAvalanche / (double) count);
      }
      
      public static int calculateAvalanche(long a, long b) {
          long difference = a ^ b;
          return Long.bitCount(difference);
      }
  
  </code></pre>
  <p>I would like to know whether this is a correct approach, or there are other ways to test the hash functions.</p>
  <p>Thanks!</p>