Mail Archives: djgpp/1996/12/01/03:12:08
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.
- Raw text -