From: Eli Zaretskii 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: References: NNTP-Posting-Host: is.elta.co.il Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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: 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 Precedence: bulk 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.