Anyone see anything wrong w/ the way I'm checking the differences in
elapsed time? I'm trying to see if the exec_time has elapsed since the
start_time.
Is exec_time correct? I'm trying to get a random number of seconds
between 0 and 4 seconds, random milliseconds, I can't use rounded off
1.0, 2.0, 3.0, 4,0 seconds, but 1.5, 2.3, 3.3, etc...
Using this, my exec_time is always a small number like 850, 3200,
2311, etc... and the start_time is a number like 1223755469, and now
is similiar. So my exec_time will never be greater than the elapsed_time.
Anyone help out?
---
// a random number of seconds between 0 and 4
int const MAX_SECONDS = 4000;
time_t now;
time_t start_time;
time_t exec_time;
start_time = time(0);
exec_time = ( rand() / (RAND_MAX + 1.0) * MAX_SECONDS);
time(&now);
elapsed_time = difftime(start_time, now);
if (exec_time > elapsed_time) {
// if the time now is longer than the time between start + seconds
// from 0 to 4 ...
}