Mail Archives: djgpp/1997/04/08/06:20:49
In article <3349B612 DOT 68C AT ucsu DOT Colorado DOT edu>, heymann AT ucsu DOT Colorado DOT edu wrote:
>I am having a major problem with my program. The random fuction does not
>seem to be working right.
>
[SNIP]
Hi,
Rather than using the AND operator use the MODULUS operatorinstead, so
random() & 9
becomes
random() % 10
This will return values between 0 and 9.
Using the AND operator as you have done simply returns the bits set
in the value returned by random and those set in 9 ie (1001), which
is why you only see the extremes of your value range.
Hope that helps
John
________________________________________________________________
Parallax Solutions Ltd. Tel.: 01203 514522
Stonecourt, Fax.: 01203 514401
Siskin Drive, Web : http://www.parallax.co.uk/~johne
Coventry CV3 4FJ Mail: johne AT parallax DOT co DOT uk
________________________________________________________________
Remember:
There is no such thing as computer error, it's 100% YOUR fault
________________________________________________________________
- Raw text -