Marshall Clow wrote:

>
> >short result = SysRandom()&0x3;  // This gets you a random number 0-3.
> >
> >or,
> >
> >short result = SysRandom()&0x7;  // This gets you a random number 0-7.
> >
> >Either of these will be *much* faster.
>
> Yes, but the ranges in your example should be 0..2 and 0..6 (not 3 and 7)

&0x03 ... 0 - 3         3 = %11,    therefore   %00, %01, %10, %11   -->  0
- 3
&0x07 ... 0 - 7         7 = %111,  therefore  %000, %001, %010, ...
,%111    -->  0 - 7

Basic (very basic) binary math.


Therefore, neither 0..2 nor 0..6.






-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to