Homework 3
comp 125-609, Goldwasser
Due: 6:00pm Tuesday, September 28, 1999 (worth 5 points)
Late Option: if submitted between 6:00pm September 28 and 6:00pm October 5, you can recieve up to 3 of 5 points. No late homeworks will be accepted after 6:00pm October 5.
Purpose: Using arrays and loops (and randomization).
Overview: The state of Illinois needs your help in developing a program for its state lottery. In the past, numbers were picked by placing a bunch of numbered ping-pong balls into a bin, following which the desired number of balls were drawn at random to select the winning numbers. Now they want a computer program which will simulate picking the numbers.

Specifically, let's assume that we are to choose 6 unique balls numbered between 1 and 40.
The same ball cannot be chosen more than once.

You should have a command button labeled "Let's Pick" which the user presses when ready. Also, each time this button is pressed, you should start from scratch and pick the next days numbers. (that is, assume all 40 balls are placed back in the bin and then repick)

Your program should display the list of the six numbers on the balls that were chosen. You may display them in any order (e.g., numerically ordered, in the order chosen)


Requirement: You code must make good use of loops and arrays. (In fact, if your program is properly written, you will find it very easy to do this week's extra credit)
How to get randomness: Visual Basic has a built in function Rnd which will return a "random" floating point number between 0.0 and 1.0. To use this to generate a random integer between 1 and N for some integer N, use the expression:
MyValue = Int(N * Rnd + 1)

Note: Everytime you restart your program, it will use the same sequence of "pseudo-random" numbers. If you want it to use a different sequence each time, add the following lines to your code:

Private Sub Form_Load()
 Randomize
End Sub

Extra Credit (1 point): Rather than "hardwire" the parameters of choosing 6 balls out of 40, allow the user to enter two values, NumBalls and NumChosen. Now, when the user clicks on the "Let's Pick" button, have your program pick NumChosen unique numbers from the set {1, 2, ..., NumBalls}.
To submit your homework you should,
  • Print out your project as follows. Click "File". Click "Print". In the Range box, select "Current project". In the Print What box, click on all three of "Form Image", "Code" and "Form as Text".
  • Save your project and form to a floppy disk
  • Place the printouts and the floppy disk inside a large manilla envelope. Please make sure that your name appears on the envelope as well as the disk and the printouts.