Jesper Lund wrote:
So, a portable way to get fractions of a second would be a fine thing (micro seconds will not always be possible; under Dos, e.g., the resolution is 1/18.2 seconds, unless you do direct hardware manipulation)...
If we forget about portability for a minute, under DOS (DJGPP) there is a libc function, uclock (), which provides (very) high-resolution timing.
Fine, I didn't know this.
It would be fine if someone could extend the time data types and functions to make use of it and the functions that are available on other systems.
Perhaps fields for 1/100 seconds and microseconds, along with flags that say if these values are good, so that the data types can be portable though the time functions will differ.
Then a built-it Randomize could use the time stamps.
For my compatibility random unit, I won't use it, but rather use a Dos call, exactly like BP.
If we forget about portability for a minute, under DOS (DJGPP) there is a libc function, uclock (), which provides (very) high-resolution timing.
Fine, I didn't know this.
Apart from the fact that this is DJGPP-specific, there is another caveat. The documentation states that the use of `uclock' *may* (on some systems) interfere with the proper working of the system time.
It would be fine if someone could extend the time data types and functions to make use of it and the functions that are available on other systems.
Perhaps fields for 1/100 seconds and microseconds, along with flags that say if these values are good, so that the data types can be portable though the time functions will differ.
Then a built-it Randomize could use the time stamps.
I understand the need for something like Randomize in game programming (I guess I am thinking too much about scientific purposes). But, as Peter pointed out, the program should only call Randomize once (at the beginning), and rely on repeated calls to the Random function to generate a sequence of numbers that -- for all practical purposes -- looks random. In that case, using hours, minutes and seconds from the system time, or the Unix approach with GetPID, should be perfectly satisfactory.
I may be missing something (I *am* totally ignorant about game programming), but to me the discussion about lack of randomness unless 1/100 or 1/1000 seconds are used sounds like calling Randomize before *each* call to Random?
Jesper Lund
P.S. I will check if there are any copyright limitations on the routine I posted yesterday.