Re: Read System Clock in Windows
- From: Skarmander <invalid@xxxxxxxxxxxxxx>
- Date: Sat, 15 Jul 2006 10:57:10 +0200
Rod Pemberton wrote:
"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
This is not the system time, this is the value of the processor-specific high resolution timer (if it exists). Using this as a seed for the C random number generator is massive overkill, and it makes your program gratuitously unportable.
How would this ever be more appropriate than time()? I can imagine some things you need high resolution timing for, but seeding a RNG isn't one of them -- and if you do need that for some reason, you should probably use your own RNG in the first place, rather than use rand() (about which the standard guarantees next to nothing).
S.
.
- Follow-Ups:
- Re: Read System Clock in Windows
- From: Rod Pemberton
- Re: Read System Clock in Windows
- References:
- Read System Clock in Windows
- From: Moikel
- Re: Read System Clock in Windows
- From: Rod Pemberton
- Read System Clock in Windows
- Prev by Date: Re: Where is a static variable stored?
- Next by Date: ungetc
- Previous by thread: Re: Read System Clock in Windows
- Next by thread: Re: Read System Clock in Windows
- Index(es):
Relevant Pages
|