// 1-14-2001 - Marianne Waage
// Program to output randomized files (called insertn.html) to stdout.

#include <fstream.h>
#include <iostream.h>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>

#define RANGE 5

// Function definitions
int anotherrandom( void );
char * itoa( int i );


int main( int argc, char** argv )
{
   ifstream file;
   string filename, pre = "../inserts/insert";
   int filenumber, i;
   char filename2[127], temp;

   // Required header for cgi
   cout << "Content-type: text/html\n\n";

   filenumber = anotherrandom();

   filename = pre + itoa( filenumber ) + ".html";

   for ( i = 0; i < filename.length(); i++)
       filename2[i] = filename[i];

   file.open( filename2 );
   while (file.read( &temp, sizeof( char )) )
      cout << temp;

   return 0;
}


int anotherrandom( void )
{
   // Initialize seed as the current time
   srandom( time( NULL ));
   
   // Return a number between 0 and RANGE
   return random() % RANGE; 
}

char * itoa( int i )
{
   char str[32];
   sprintf(str, "%d", i);
   return strdup(str);
}

