Also you need to include ctime/time.h library and do this in main:
srand((unsigned)time(0));//Seed pseudo random number generator
I am not very familiar with the way you are timing your code, but I have done something similar before:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
clock_t NewTime = clock();
clock_t PrevTime = NewTime;
while (1)
{
NewTime = clock();
checkTime += (double)(NewTime - PrevTime);
PrevTime = NewTime;
if (checkTime > (double)(CLOCKS_PER_SEC))
//Multiply CLOCK_PER_SEC by how often you want to update you code (in secs)
{
//Some Code in here
checkTime -= (double)(CLOCKS_PER_SEC);
}
}