Re: Read System Clock in Windows




"Moikel" <obviouslyadummy@xxxxxxxxx> wrote in message
news:1152915795.036894.34450@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,

I'm writing a program that requires that I generate random numbers. I'm
using the C rand()function. I want to use the system clock as a seed
for the function. How do I read the system clock in Windows? (Please
state any libraries I'm going to need etc).


Yahoo'd for the 'rdtsc' instruction and Windows:

QueryPerformanceCounter()
http://msdn.microsoft.com/library/default.asp?url=/library/
en-us/winui/winui/windowsuserinterface/windowing/timers/
timerreference/timerfunctions/queryperformancecounter.asp


You could also do something along these lines:

unsigned long long rdtsc(void)
{
unsigned long long cycles=0;
#ifdef __DJGPP__
__asm__ __volatile__(
"rdtsc\n"
:"=A"(cycles)
);
#endif
#ifdef __WATCOMC__
_asm {
rdtsc
mov dword ptr [cycles], eax
mov dword ptr [cycles+4], edx
}
#endif
return cycles;
}

The DJGPP code should work for GCC compilers. The OpenWatcom code should
work for MS compilers. If not, they are close...


Rod Pemberton



.