


//  MAIN.CC    Generate a text file of binary chromosomes, random.  
//             Ask console user for chromosome length L and number of
//             chromosomes desired, N.


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

void main() {
       char tempchar;
       int i,j,k,numchroms,chromlength;
       FILE *out;

       cout << "\n\n ********************************************************* \n";
       cout << "RANDOM CHROMOSOME GENERATOR (outputs to file named `input')";
       cout << "\n\n ********************************************************* \n";
       cout << "\n\n How many chromosomes? ";
       cin >> numchroms;
       cout <<  "\n How many bits per chromosome? ";
       cin >> chromlength;
       cout << "\n";
  
       out = fopen("input","w");              //  Open a file for writing.
                                              //  NOTE:  No error handling!
       for(k = 0; k < numchroms; k++)         //  Main loop, once thru for each chrom.
          {
            for (i = 0; i < chromlength; i++) //  Inner loop, once thru for each bit.
               {
                   j =  rand() % 2;            // Generate int "0" or "1", random, even chance.
                   fprintf(out,"%c",'0'+j);   // Write bit to file, forcing coercion to char.
               };
            fprintf(out,"\n");                // End line.
           }

       fprintf(out,"\n");         //  End last line with newline char.
       fclose(out);               //  Close file "input".
       cout << "done\n";          
  }


