Date: Thu, 21 Jan 1999 19:27:05 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: FireFoX McLouD cc: djgpp AT delorie DOT com Subject: Re: rand() function In-Reply-To: <36A72C2A.3DAF8CFE@cryogen.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com On Thu, 21 Jan 1999, FireFoX McLouD wrote: > How can I redefine the RAND_MAX parameter to use rand() with low > numbers? You can't. Even if you do redefine RAND_MAX, the behavior of `rand' won't change, since `rand' was compiled with the original definition of RAND_MAX. The simplest way to get random integers from 0 to N is to say this: rand()%(N+1) But beware: for small values of N you will get not-so-random numbers, because the low-order bits of what `rand' produces are known to be not so random. There are better ways, if the last caveat bothers you. One of them is to use `random' instead of `rand'. For others, you will have to find a good book on random numbers, it's too complicated to tell it here.