Date: Sun, 1 Dec 1996 09:50:58 +0200 (IST) From: Eli Zaretskii To: Paul Dixon

Cc: djgpp AT delorie DOT com Subject: Re: Random numbers ... In-Reply-To: <199611301124.LAA09903@mailhost.sm.ic.ac.uk> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Sat, 30 Nov 1996, Paul Dixon wrote: > > while ( tolower( getchar( ) ) != 'q' ) > > { > > r = random( ) % 501; /* 0 to 500 */ > > printf( "%d", r ); > > } > > I hate to say this, but it is NOT generally advisable to use MODULUS to > force a random number into a specified range if you really care about the > quality of the random numbers. In general, yes, but not with `random'. Its algorithm makes sure that all the bits generated by random() are usable. For example, random()&01 should produce a random binary value.