Results 1 to 2 of 2

Thread: printing random numbers...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    20

    printing random numbers...

    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 questions never why, its always how" - Kevin David Mitnick

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The easiest way is creating an array and using the random number as index into the array. Like:
    Code:
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width