www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/21/08:41:48

Message-ID: <32945932.4386@pobox.oleane.com>
Date: Thu, 21 Nov 1996 14:29:22 +0100
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
CC: djgpp AT delorie DOT com
Subject: Re: Problems with djgpp 2.01
References: <Pine DOT SUN DOT 3 DOT 91 DOT 961121130139 DOT 23836A-100000 AT is>

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.

- Raw text -


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