Message-ID: <32945932.4386@pobox.oleane.com> Date: Thu, 21 Nov 1996 14:29:22 +0100 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: Eli Zaretskii CC: djgpp AT delorie DOT com Subject: Re: Problems with djgpp 2.01 References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii wrote: > > Not true. The following program, compiled with DJGPP v2.01, will > continuosly print random integers until you press a key. It works for > me. So there is no need to call srand. > Still, it *is* bad practice not to initalise rand() with srand() in portable programs: many implementations of rand() use linear congruential generators: they calculate y=ax+b mod(c) (where x is the previous value, and y the output of rand()) Now, some implementations use b=0, as it saves an add per call, an can be as good as the other one... In this case, you can use any seed *except* 0, which will always output the same value (0)... As rand() is an ANSI function, but as its implementation can vary from one library to the other, it is wise to always seed rand() in portable programs, and *never* use a 0 seed.