Date: Wed, 26 Nov 1997 12:53:28 -0800 (PST) Message-Id: <199711262053.MAA16591@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: George Foot , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: randomize? Precedence: bulk At 05:28 11/25/1997 GMT, George Foot wrote: >Also note that if you're from a Borland background you'll be expecting >the `random' function to take a parameter (the smallest integer that >will never be returned) -- in djgpp this is not the case. The `rand' >function returns an integer from 0 to RAND_MAX and the `random' >function returns an integer from 0 to MAXINT. In practice, these >maxima are both the same, and equal to the largest number that can be >expressed as a (32-bit) integer. To restrict the range of the >numbers, use the divison-remainder operator, `%'. I'll make the usual comment here that for the `rand' RNG, the low-order bits, which are what you get when using `%', are sometimes not as random as one would like. You can fix this with some casts: (int)((double)rand()/RAND_MAX)*largest_random_number_you_want `random' doesn't have this problem, but also is not ANSI. The discrepancy is due to legal issues and is being considered. Nate Eldredge eldredge AT ap DOT net