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.
Printable View
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.
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;
}