Puzzle R4

Histogram N random integers in the range 0..9

[M-14] Write a main() program that generates a large number of random integers in the range 0..9. Create a histogram of the numbers. A histogram is an array that holds the number of times each integer occurred. Here is one run of the program, for N==100000000:

  0: 10001193
  1: 10001982
  2: 10003463
  3: 10002130
  4:  9999796
  5: 10003199
  6:  9997985
  7: 10000221
  8:  9997708
  9:  9992323

You should expect each histogram cell to contain about one tenth the total, about 10000000. Of course, there will be small deviations above and below that value. A really big deviation would be a sign that something is wrong.



Answer         Next Page         Previous Page Home