Date: Sat, 28 Mar 1998 10:40:52 -0800 (PST) Message-Id: <199803281840.KAA16578@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: real random numbers Precedence: bulk At 06:24 3/26/1998 -0500, John M. Aldrich wrote: >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 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. Bit of a correction. `gettimeofday' returns its value in *microseconds*, but it is only accurate to the nearest 55 milliseconds (i.e. DOS timer tick). I suppose it is theoretically possible to run faster than this. There's a similar discussion going on about how to get a fairly unique PID. You could check the archives and try some of those solutions. (Check the djgpp-workers archive too.) Nate Eldredge eldredge AT ap DOT net