I have made a program that generates random numbers. It takes arguments from the command line like this:
Usage: argv [-n | -c [val]] [min-max] [num]
Default behaviour is to print [num] random numbers, ranging from [min] to [max], with a newline after each number. The option "-n" will cause no newlines to be printed between each value, OR, "-c val" will print an ascii value "val", between each number.
Here is the main processing function of the program (all the arguments have been checked):
I wonder if any bit shifting could be done (or any other tricks) to speed this up...
/* Main function to output random numbers.
It outputs "num" random numbers, between "min" and "max",
with "ch" between each number. */
(int ch, int min, int max, unsigned long int iterations)
register long int rannum;
register unsigned int diff;
register unsigned long int num = iterations;
/* Work out offset value, increment as rand()
could return 0 as lowest value */
diff = max - min;
/* Any better ideas? */
for( ; num>0 ; num-- )
rannum = rand();
rannum %= diff;
rannum += min;
if( ch )