Re: Read System Clock in Windows



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.
.



Relevant Pages

  • Re: Read System Clock in Windows
    ... How do I read the system clock in Windows? ... This is not the system time, this is the value of the processor-specific ... high resolution timer. ... your own RNG in the first place, rather than use rand(about which the ...
    (comp.lang.c)
  • [PATCH] /dev/time for Linux, inspired by Plan 9
    ... reading or writing text strings to a special file named /dev/time. ... epoch seconds, nanoseconds since start of epoch, ... /dev/time sets the system clock to the given number of epoch seconds. ... +that is provided by the Plan 9 operating system from Bell Laboratories. ...
    (Linux-Kernel)
  • [PATCH] /dev/time for Linux, inspired by Plan 9
    ... reading or writing text strings to a special file named /dev/time. ... nanoseconds since boot, and nanoseconds per second. ... to /dev/time sets the system clock to the given number of epoch seconds. ... +that is provided by the Plan 9 operating system from Bell Laboratories. ...
    (Linux-Kernel)
  • Re: Read System Clock in Windows
    ... I'm writing a program that requires that I generate random numbers. ... I want to use the system clock as a seed ... But the OP should be concerned about including the correct header. ... Remove del for email ...
    (comp.lang.c)
  • Re: Read System Clock in Windows
    ... Moikel said: ... I'm writing a program that requires that I generate random numbers. ... I want to use the system clock as a seed ... rjh at above domain ...
    (comp.lang.c)