Mail Archives: djgpp/1997/06/11/17:48:33
>I was going to use rawclock() to seed the random number generator in a
>DJGPP/Allegro program I'm writing, as the info file, libc.inf, said that
>rawclock() returns the number of clock ticks since midnight (I was hoping
>that it would be similar to saying RANDOMIZE TIMER in BASIC <hehe>).
>Here, I'll quote it for you:
>
>[deleted]
>Well, the problem is, it doesn't return the number of clock ticks since
>midnight, but rather the number of somethings (clock ticks I suppose)
>since the first time it was called! I know that some of the time.h
>functions are specifically described as returning the number of something
>since the first call, but I also know that (as you can see) rawclock()
>isn't supposed to work that way (according to the reference manual,
>anyways).
>
>Is there something I didn't do? Do I have to call some function or set
>some flag to set it up? I know it's not caused by anything other than
>DJGPP itself, as this small program I just made yields the same results:
>[deleted]
Yes, I know about this. I had the same problem. It does indeed return clock
ticks since first called. This is either a bug in the libc code, or very
poorly documented. I believe you have two options:
1. Use time(NULL) to seed the RNG. This works but only has a 1-second
resolution. If you are going to be running it at very similar times this may
decrease randomness :-)
2. Fix the library. I have written a fixed version that performs as
documented. This code needs to be rawclock.c:
---- cut -----
/* Fixed rawclock.c */
#include <time.h>
#include <go32.h>
#include <libc/farptrgs.h>
unsigned long
rawclock(void)
{
return _farpeekl(_dos_ds, 0x46c);
}
---- cut -----
You then compile it to a .o file, and use `ar' to put it into libc.a:
gcc -c rawclock.c
ar rs /your_djgpp_directory/lib/libc.a rawclock.o
This works for me. It's theoretically possible that something depends on the
broken version, and this would break that. But I seriously doubt it.
Perhaps a fix like this should be made to the next DJGPP release.
Good luck!
Nate Eldredge
eldredge AT ap DOT net
- Raw text -