Timing

This is a discussion on Timing within the C++ Programming forums, part of the General Programming Boards category; Hello everyone. What I'm trying to do is generate a new random number every second. I need this for a ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    6

    Timing

    Hello everyone.
    What I'm trying to do is generate a new random number every second. I need this for a program I'm working on. It's the timing that I'm not sure how to do. The randomizing part I think I've got. Thank you in advance.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Code:
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    int main(int argc, char** argv) {
      
      srand(time(NULL));
      time_t last = time(NULL);
      int delay = 1;
    
      while( true ) {
        if( (time(NULL) - last) > delay ) {
          cout << rand() << endl;
          last = time(NULL);
        }
      }
    
      return 0;
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Timing basic operations in C++
    By StevenGarcia in forum C++ Programming
    Replies: 9
    Last Post: 09-18-2007, 02:10 AM
  2. Performance Timing Function
    By rosicky2005 in forum C++ Programming
    Replies: 11
    Last Post: 05-31-2007, 03:09 PM
  3. My Timing System
    By jmd15 in forum Windows Programming
    Replies: 4
    Last Post: 01-01-2006, 10:43 PM
  4. Games - timing
    By Magos in forum Game Programming
    Replies: 7
    Last Post: 03-06-2004, 10:32 AM
  5. Timing in Windows
    By steinberg in forum Windows Programming
    Replies: 3
    Last Post: 07-14-2002, 12:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21