"Dave Sill" <[EMAIL PROTECTED]> wrote:

>--IPiIw4QAe+
>Content-Type: text/plain; charset=us-ascii
>Content-Description: message body text
>Content-Transfer-Encoding: 7bit
>etc.

Argh. Forgot about my Emacs' broken MIME. Here's the program:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main(int argc, char **argv)
{
  int hash[10000], i;
  int size=16, reps=100000000, seed=0;
  long j;
  float mean, variance=0, stddev;

  if (argc >= 2) {
    sscanf (argv[1], "%d", &size);
    if (size > 10000)
      exit (1);
  }
  if (argc >= 3)
    sscanf (argv[2], "%d", &reps);
  if (argc >= 4)
    sscanf (argv[3], "%d", &seed);
  mean=reps/size;
  printf ("size=%d, reps=%d, seed=%d\n", size, reps, seed);
  for (i=0; i<size; i++) {
    hash[i]=0;
  }
  srand48 (seed);
  for (i=0; i<reps; i++) {
    j=lrand48();
    hash[j%size]++;
  }
  for (i=0; i<size; i++) {
    printf ("%d: %d\n", i, hash[i]);
    variance += pow(hash[i] - mean, 2.0);
  }
  variance /= (float)size-1;
  stddev=sqrt(variance);
  printf ("mean=%f, variance=%f\n", mean, variance);
  printf ("stddev=%f (%f%)\n", stddev, stddev/mean*100);
}

-Dave

Reply via email to