• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 4 pages
Other

Computer Science 101: Assignment 1 on Random Number Generation and Command Line Parameters

Document preview thumbnail
Preview 1 out of 4 pages

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.

Content preview

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.

Document information

Uploaded on
July 4, 2025
Number of pages
4
Written in
2026/2027
Type
Other
Person
Unknown
Free
Download

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
LectScotty
4.1
(28)
Sold
202
Followers
6
Items
5363
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions