Function to Make A List of Pseudo-Random Numbers
/*
FUNCTION: makelist
PURPOSE: Produces a specified number (how_many)
of random integers between low and
high, writes the number of random
integers to the output file, and writes
the random integers out to the file.
CALLING SEQUENCE (include these parameters when
executing the program, in the order
listed):
how_many low high outputFileName
EXAMPLE: a.out 100 10 999 my_data
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *outfile; /* output file */
int how_many=atoi(argv[1]), /* how many random numbers to generate */
low=atoi(argv[2]), /* lowest possible value */
high=atoi(argv[3]), /* highest possible value */
i; /* control variable */
/* open output file */
if((outfile = fopen(argv[4],"w")) == NULL)
{
printf("Cannot open output file, %s\n",argv[4]);
exit(-1);
}
/* produce random numbers and print to outfile */
fprintf(outfile,"%d\n",how_many);
for(i=0;i<how_many;i++)
{
fprintf(outfile,"%d\n", (low+
(int)(((float)random()/0X7FFFFFFF)*high-low+1)));
}
return 0 ;
}