PDA

Click to See Complete Forum and Search --> : printing random numbers...


3nC0d3r
Dec 15th, 2002, 03:24 PM
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.

CornedBee
Dec 15th, 2002, 06:16 PM
The easiest way is creating an array and using the random number as index into the array. Like:

int randNum = rand() % MAX_WANTED_VALUE_PLUS_ONE;
++numTracker[randNum];
cout << randNum << '\n';


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.