C++ Pseudo Random Source Code

/*
Sloppy code written by David Rainey as requested by sloppy mathmatician,
Andrew Williamson
This program will prompt the user for the number of characters to generate
and the file to store the results in.

Only lower-case letters a-z and spaces are generated

A random number between 0 and 26 is returned. 0 represents a space in the
output file, 1 represents ‘A’, etc.
*/
#pragma hdrstop
#include <condefs.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>

//—————————————————————————
#pragma argsused
int main(int argc, char **argv)
{

int iNumber;
char chLetter;
int iNumChars=0;
unsigned long ulNumChars=0;
char szFile[256];
FILE *pOutFile;

printf(“\nHow many thousand characters would you like to generate: “);
scanf(“%d”, &iNumChars);

ulNumChars = iNumChars * 1000;

clrscr();
fflush(stdin);
printf(“\nEnter the file to store the results in: “);
scanf(“%s”, szFile);

clrscr();

// open the file
pOutFile = fopen(szFile, “w+”);
if ( !pOutFile )
{
printf(“\nUnable to open output file %s”, szFile);
return(1);
}

randomize();
for ( unsigned long i=0; i<ulNumChars; i++ )
{
iNumber = rand() % 27;
if ( iNumber == 0 )
chLetter = ‘ ‘;
else
chLetter = ‘a’ + iNumber – 1;

fprintf(pOutFile, “%c”, chLetter);

}
fclose(pOutFile);

printf(“\n\n%u characters generated in %s\n”, ulNumChars, szFile);

return 0;
}