Mail Archives: djgpp/1998/03/27/21:26:01
hat AT se-46 DOT wpa DOT wtb DOT tue DOT nl wrote:
>
> As some people already have pointed out, this only works when your
> program runs at least for a single second.
> Does somebody know how to take care of getting a different value each
> time you run a program, no matter how often in a single second you start
> it ?
The header <sys/time.h> declares a function called gettimeofday()
(q.v.). The struct returned by this function contains the current GTM
time accurate to the millisecond. Unless your program runs faster than
once every millisecond (very difficult to do on a DOS box), this value
should be adequate to use as a seed.
If you want to get really esoteric, when your program exits you could
have it produce a random number, write it to disk, and then read it in
the next time to use as the seed.
--
---------------------------------------------------------------------
| John M. Aldrich |"Men rarely (if ever) manage to dream |
| aka Fighteer I |up a god superior to themselves. Most |
| mailto:fighteer AT cs DOT com |gods have the manners and morals of a |
| http://www.cs.com/fighteer |spoiled child." - Lazarus Long |
---------------------------------------------------------------------
- Raw text -