howMany only counts the occurrences of a particular value, and we are interested in seeing how many times each value appears. We can solve that problem with a loop:
int numValues = 20;
int upperBound = 10;
vector<int> vector = randomVector(numValues, upperBound);
cout << "value\thowMany";
for (int i = 0; i < upperBound; i++) {
cout << i << '\t' << howMany(vector, i) << endl;
}
Notice that it is legal to declare a variable inside a for statement. This syntax is sometimes convenient, but you should be aware that a variable declared inside a loop only exists inside the loop. If you try to refer to i later, you will get a compiler error.
In each case, the number of appearances is within about 1% of the expected value (10,000), so we conclude that the random numbers are probably uniform.
the difference between actual and expected number of appearances increases
Correct! The numbers go from being off by less than 5 to more than 100.
the difference between actual and expected number of appearances decreases
Incorrect! Take a look at the numbers again!
the percent by which the number of appearances differs from the expected number increases
Incorrect! Take a look at the numbers again!
the percent by which the number of appearances differs from the expected number decreases
Incorrect! As we continue to increase the size of numValues, the percent by which the number of appearances differes from the expected value approaches 0.