CSCI 1100 - Assignment #6

CSCI 1100 - Assignment #6

CSCI 1100 - Assignment #6

Due: 8:30 am, Friday, March 1, 2002

This program must be submitted electronically via a submit script that will be ready by Monday, February 25th.

TestRandom.java

Design and implement an application that tests the distribution of a number of trials of random numbers. The minimum and maximum random numbers to generate, and the number of trials to conduct will be specified by the user.

After all the trials have been completed, you must find the the minimum and maximum number of occurrences counted over the full range of random numbers. You must then output a histogram of the distribution of occurrences (scaled so that bars of the histogram have a maximum width of 60 stars. Following the output of the histogram, the maximum and minimum occurrences counted (and for which random number they occurred should be output.

The first output your program should produce is your identification followed by a short description of the program. You should then prompt for the minimum and maximum values for the range and the number of trials. Error check so that the width of the specified range is positive but also less than or equal to 50. Also, the number of trials should be a positive value. The bounds for the random numbers may be located anywhere in the range of integers (i.e -23412..-23400 is a valid range (width of range is 13)).

Sample output is as follows. Please ensure that your program behaves EXACTLY the same way, including the insertion of some additional new line characters so that when the submit script is run (and the actual input does not appear in the output), the output will begin on a new line. Of course, the actual distribution of random numbers will vary each time, but check and make sure that you are generating random numbers to cover the full range.

From the mark6 file created as a result of the submit script I ran with my solution:

*****************OUTPUT****************

------input of -2, 2, 10000:-----

***************************************

* TestRandom *

* *

* Kirstie Hawkey *

* *

* B00001149 *

***************************************

This program displays the distribution of random numbers in any range (with a width of 50 or less). The number of trials must also be specified.

Specify the minimum value for the range: Specify the maximum value for the range: Specify the number of trials:

Histogram of occurrences for each random number:

-2:********************************************************

-1:********************************************************

0:**********************************************************

1:************************************************************

2:********************************************************

Minimum number of occurrences: 1959 for the random number -2.

Maximum number of occurrences: 2096 for the random number 1.

------input of 2, -2, 10000, then 0, 1, 50000:-----

***************************************

* TestRandom *

* *

* Kirstie Hawkey *

* *

* B00001149 *

***************************************

This program displays the distribution of random numbers in any range (with a width of 50 or less). The number of trials must also be specified.

Specify the minimum value for the range: Specify the maximum value for the range: Specify the number of trials:

ERROR: The range must have a width of 1 to 50.

Specify the minimum value for the range: Specify the maximum value for the range: Specify the number of trials:

Histogram of occurrences for each random number:

0:************************************************************

1:***********************************************************

Minimum number of occurrences: 24907 for the random number 1.

Maximum number of occurrences: 25093 for the random number 0.

------input of 0, 50, 100, then 1, 50, 100:-----

***************************************

* TestRandom *

* *

* Kirstie Hawkey *

* *

* B00001149 *

***************************************

This program displays the distribution of random numbers in any range (with a

width of 50 or less). The number of trials must also be specified.

Specify the minimum value for the range: Specify the maximum value for the range: Specify the number of trials:

ERROR: The range must have a width of 1 to 50.

Specify the minimum value for the range: Specify the maximum value for the range: Specify the number of trials:

Histogram of occurrences for each random number:

1:***

2:***

3:*****

4:

5:**

6:***

7:*

8:***

9:*

10:**

11:

12:**

13:***

14:***

15:**

16:*

17:**

18:**

19:**

20:***

21:***

22:**

23:**

24:*

25:***

26:**

27:*

28:***

29:*

30:***

31:**

32:**

33:*

34:*

35:*

36:

37:*

38:**

39:

40:****

41:**

42:***

43:**

44:**

45:**

46:***

47:**

48:*

49:*****

50:

Minimum number of occurrences: 0 for the random number 4.

Maximum number of occurrences: 5 for the random number 3.

*****************END OF OUTPUT*********