Mail Archives: djgpp/1999/11/16/14:31:06
> > Hello Fellow DJGPPers!
> >
> > I have a question concerning the DJGPP time() function.
> > Can you tell me the frequency in which time() returns the time...
> > Is it 1 second increments? I'm trying to settle an argument with a
> > co-worker, who argued that it is in Microsecond increments.
>
> Yes, it's in seconds. (Seconds since January 1, 1970 if I recall
> correctly.)
Okay...That answers a part of the question....
Actually, This is an argument that grown out of a function that uses the
time() function to seed a Random number generator...
You see, me and my collegue is developing a program that would generate
random numbers for use in a random file display utility (Well, the idea is
this...You want the user to be presented with a text file...One out
of...let's say, 4...and should be presented as randomly as possible)
Well, the problem is, I use DJGPP and the srand(time(0)); call to seed the
random generator, while my collegue uses Borland C++ 5.0 and a randomize()
function in his stdlib.h...After I chewed him out for using a propietary
non-standard function to seed the random number, I pointed out that while
using the DJGPP srand(time(NULL)) call, the random function if called in
very rapid succession would yield preictable results, while using
rawclock() (18.2 ticks/sec) would yield marginally better
results...however, he claims that time() works in the Microsecond level
and should not return predictable random results...
The problem is...I tested the code in DJGPP and MSVC6 and they both yeild
precdictable results if the program is run in less than 1 seconds of
time...While I did not test the Borland Code (Because I don't have
Borland, and the Borland code won't compile under DJGPP) I cannot say for
sure whether my collegue's right (Well, partly right...Perhaps Borland's
C++ 5 does have a Microsecond level time() function) or I'm right (That
all time() functions for x86 machines run on the Second level)
can anyone with experience on Cross-compiler development please shed some
light to this?
- Raw text -