Y
yezi
HI , all :
I want to control the event gap onto microsecond level , so I called
the function :
nanosleep(&req, &req);
according to the description of this function, I should set the
The structure timespec is used to specify intervals of time with
nanosecond precision. It is specified in <time.h> and has the
form
struct timespec
{
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
The value of the nanoseconds field must be in the range 0 to
999 999 999.
The code to control tv_nsec is:
float random;
int perCentage = 10;
int baseGap = 20000;
random = drand48();
req.tv_nsec = baseGap*(1- (perCentage/100) +
random*2*(perCentage/100));
printf("the time is %f",req.tv_nsec);
The output is :
baseGap is 20000
the random number is 8.700579e-01
the time is 1.000000395
My question is the time suppose is :
20000*(1- 0.1 + 2*0.8*0.1);
should around 20000.
BUt the value is not .
Why, thanks for any hint.
I want to control the event gap onto microsecond level , so I called
the function :
nanosleep(&req, &req);
according to the description of this function, I should set the
The structure timespec is used to specify intervals of time with
nanosecond precision. It is specified in <time.h> and has the
form
struct timespec
{
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
The value of the nanoseconds field must be in the range 0 to
999 999 999.
The code to control tv_nsec is:
float random;
int perCentage = 10;
int baseGap = 20000;
random = drand48();
req.tv_nsec = baseGap*(1- (perCentage/100) +
random*2*(perCentage/100));
printf("the time is %f",req.tv_nsec);
The output is :
baseGap is 20000
the random number is 8.700579e-01
the time is 1.000000395
My question is the time suppose is :
20000*(1- 0.1 + 2*0.8*0.1);
should around 20000.
BUt the value is not .
Why, thanks for any hint.