delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/02/06:47:24

From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: rand and random
Date: Tue, 2 Nov 1999 11:25:49 +0200
Organization: NetVision Israel
Lines: 21
Message-ID: <Pine.SUN.3.91.991102112306.20126N-100000@is>
References: <s1n73iu5iqi71 AT corp DOT supernews DOT com> <p6obOB+BRMP7QeUGn1Z+l2JBPBVt AT 4ax DOT com> <Pine DOT SUN DOT 3 DOT 91 DOT 991031100828 DOT 2988f-100000 AT is> <xIgeOAnzj2KaFWlGUNnv=obD+Vkp AT 4ax DOT com>
NNTP-Posting-Host: is.elta.co.il
Mime-Version: 1.0
X-Trace: news.netvision.net.il 941534673 617 199.203.121.2 (2 Nov 1999 09:24:33 GMT)
X-Complaints-To: abuse AT netvision DOT net DOT il
NNTP-Posting-Date: 2 Nov 1999 09:24:33 GMT
X-Sender: eliz AT is
In-Reply-To: <xIgeOAnzj2KaFWlGUNnv=obD+Vkp@4ax.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 2 Nov 1999, Damian Yerrick wrote:

> > `rand' returns a random integer between 0 and RAND_MAX.  The latter is
> > defined on stdlib.h, and is much larger than 32K.
> 
> I thought some C standard defined rand() as
> 
> #define RAND_MAX 0x7fff
> int rand(void)
> {
>   mySeed = (mySeed * 1103515245) + 12345;
>   return (mySeed & 0x7fff0000) >> 16;
> }

This is the *minimal* version of the generator recommended by the 
Standard.  It is compatible with the Standard's requirement that an int 
be at least 16-bit wide.

Most (if not all) 32-bit implementations provide a generator with
the full 32-bit range.

- Raw text -


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