#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

double expovariate(double lambda)
{
  double u;
  u = random() / (double)RAND_MAX;
  return -log(1.0 - u) / lambda;
}

const char fill[] = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\n";

int main(int argc, char* argv[])
{
  struct timeval tv;
  long bytes;
  long average;
  int i;
  if (argc < 3) {
    fputs("usage: fake-msg average header [header ...]\n", stderr);
    exit(1);
  }
  average = atol(argv[1]);
  gettimeofday(&tv, 0);
  srandom(tv.tv_sec ^ tv.tv_usec);
  bytes = 1.0 / expovariate(average);

  for (i = 2; i < argc; i++) {
    puts(argv[i]);
    bytes -= strlen(argv[i]) + 1;
  }
  putchar('\n'); --bytes;
  
  while (bytes >= 65) {
    fputs(fill, stdout);
    bytes -= 65;
  }
  if (bytes > 0)
    fputs(fill+65-bytes, stdout);
  return 0;
}
