Computer Science 101: Assignment 1 on Random
Number Generation and Command Line Parameters
Reminders:
Follow the submission instructions.
Remember to comment your code!
0) Random number generation. (50 pts)
Often, computer scientists, statisticians, physicists, social scientists, and mathematicians need a
list of random numbers. Political pundits also find lists of random numbers useful to provide
'statistical' evidence of their arguments.
Implement a tool to generate and print a sequence of 10 random numbers. Each random
number should be an integer in the range from
0 to 100, inclusive (that means both 0 and 100 should have a chance of appearing). I do not
expect you to implement your own random number generator. I expect you to use the standard
way of obtaining randomness in a secure fashion.
$ ./grand
56 77 91 2 33 40 72 100 6 2
Augment your program to take a command line parameter specifying how many random
numbers to generate. That is, if grand is invoked by:
$ ./grand 4
it will output 4 random numbers from 0 to 100, inclusive. Make sure your program does
something sensible if the supplied argument is not a valid integer. There should not be an
arbitrarily imposed upper limit to this number (in other words, do not have an artificial cap on
the value of the argument).
Since it is easy to forget how to use programs, it is often useful to provide a well-known
command line switch (or parameter) that tells the user how to invoke the program. Augment
your program to recognize two more command line arguments, '-h' and '--help' that prints out
the usage information for the program. For example,
$ grand -h
and
$ grand --help
should output the following usage information:
grand [-h | --help] : output this usage message.
grand [n] : print out n random integers in [0,100]
Finally, augment your program to print out its version. Don't forget to add this usage case to
your help dialog.
Number Generation and Command Line Parameters
Reminders:
Follow the submission instructions.
Remember to comment your code!
0) Random number generation. (50 pts)
Often, computer scientists, statisticians, physicists, social scientists, and mathematicians need a
list of random numbers. Political pundits also find lists of random numbers useful to provide
'statistical' evidence of their arguments.
Implement a tool to generate and print a sequence of 10 random numbers. Each random
number should be an integer in the range from
0 to 100, inclusive (that means both 0 and 100 should have a chance of appearing). I do not
expect you to implement your own random number generator. I expect you to use the standard
way of obtaining randomness in a secure fashion.
$ ./grand
56 77 91 2 33 40 72 100 6 2
Augment your program to take a command line parameter specifying how many random
numbers to generate. That is, if grand is invoked by:
$ ./grand 4
it will output 4 random numbers from 0 to 100, inclusive. Make sure your program does
something sensible if the supplied argument is not a valid integer. There should not be an
arbitrarily imposed upper limit to this number (in other words, do not have an artificial cap on
the value of the argument).
Since it is easy to forget how to use programs, it is often useful to provide a well-known
command line switch (or parameter) that tells the user how to invoke the program. Augment
your program to recognize two more command line arguments, '-h' and '--help' that prints out
the usage information for the program. For example,
$ grand -h
and
$ grand --help
should output the following usage information:
grand [-h | --help] : output this usage message.
grand [n] : print out n random integers in [0,100]
Finally, augment your program to print out its version. Don't forget to add this usage case to
your help dialog.