Re: Read System Clock in Windows
- From: "Rod Pemberton" <do_not_have@xxxxxxxxxxx>
- Date: Sat, 15 Jul 2006 03:09:51 -0400
"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
.
- Follow-Ups:
- Re: Read System Clock in Windows
- From: Skarmander
- Re: Read System Clock in Windows
- References:
- Read System Clock in Windows
- From: Moikel
- Read System Clock in Windows
- Prev by Date: Re: fflush()
- Next by Date: Problem with keyboard input for my very little OS
- Previous by thread: Re: Read System Clock in Windows
- Next by thread: Re: Read System Clock in Windows
- Index(es):