delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/26/14:31:56

Date: Tue, 26 Aug 1997 11:30:49 -0700 (PDT)
Message-Id: <199708261830.LAA11115@adit.ap.net>
Mime-Version: 1.0
To: ah897 AT detroit DOT freenet DOT org (Heathen), djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Random numbers...
Cc: xyy AT infonie DOT be

At 11:52  8/20/1997 GMT, Heathen wrote:
>In article <01bcaa71$4c08c200$0d5e4ec2 AT xyy>, xyy AT infonie DOT be says...
>>I still can't obtain truly random numbers with the srand(), random(), and
>>rand() functions, because, whatever the seed number i put in srand(), it is
>>_always the same results.
>>
>>What can i do about it ?
>Hey here's a neat trick I used with Borland's C++ 3.0 from awhile ago for
Random 
>Number Generater:
>            #include <dos.h>
>            Main(){
>            int Jims_Rand_Num;
>            gettime(&ti_hund);
>            Jims_Rand_Num = ti_hund;
>            
>            }
>
The very best method is to seed the random number generator from the current
time. In DJGPP, that looks like this:

#include <time.h>
#include <stdlib.h>

/* ... */
   srand(time(NULL));
/* Now use rand() to get random numbers. */

HTH

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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