how can i print say 10000 random numbers and the end it create a report of how many times each number was printed?
thankyou for any help.
Printable View
how can i print say 10000 random numbers and the end it create a report of how many times each number was printed?
thankyou for any help.
The easiest way is creating an array and using the random number as index into the array. Like:
In the end you simply loop through the array (numTracker) and print out the array values. If the array was initially all 0 (you should see to that) then the final values will be the amount some number has occurred.Code:int randNum = rand() % MAX_WANTED_VALUE_PLUS_ONE;
++numTracker[randNum];
cout << randNum << '\n';