www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/28/17:16:15

Date: Sat, 28 Mar 1998 10:40:52 -0800 (PST)
Message-Id: <199803281840.KAA16578@adit.ap.net>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: real random numbers

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 <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.

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



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019