J
Joe
I'm trying to add the current time + a randomly generated time w/
millisecond precision, but the numbers aren't making sense.
If I add rand_time + now_time on my calculator, I get a different result
than what's in sched_time. Anyone see what I'm doing wrong?
These are my results ..
rand_time = 4958.128418
now_time = 1225033344.000000
sched_time = 1225038336.000000
(my calc says rand_time + now_time = 1225038302.13)
struct timeval now;
gettimeofday(&now, NULL);
float rand_time = random_time();
float now_time = now.tv_sec + (now.tv_usec / 1000000.0);
float sched_time = now_time + rand_time;
printf("rand_time = %f\n", rand_time);
printf("now_time = %f\n", now_time);
printf("sched_time = %f\n", sched_time);
float random_time()
{
int const MAX_MILLISECONDS = 5000;
return (rand() / (RAND_MAX + 1.0) * MAX_MILLISECONDS);
}
millisecond precision, but the numbers aren't making sense.
If I add rand_time + now_time on my calculator, I get a different result
than what's in sched_time. Anyone see what I'm doing wrong?
These are my results ..
rand_time = 4958.128418
now_time = 1225033344.000000
sched_time = 1225038336.000000
(my calc says rand_time + now_time = 1225038302.13)
struct timeval now;
gettimeofday(&now, NULL);
float rand_time = random_time();
float now_time = now.tv_sec + (now.tv_usec / 1000000.0);
float sched_time = now_time + rand_time;
printf("rand_time = %f\n", rand_time);
printf("now_time = %f\n", now_time);
printf("sched_time = %f\n", sched_time);
float random_time()
{
int const MAX_MILLISECONDS = 5000;
return (rand() / (RAND_MAX + 1.0) * MAX_MILLISECONDS);
}