>Hi Geoffrey,
>
>I don't think sysRandomMax can be changed, Geoffrey.  What you do
>instead is to get the modulus (remainder after division) like this:
>
>short result = SysRandom()%5;
>
>If you're programming a game, you should know that a '%' operation is
>actually a divide, and is to be avoided.  What you can do in this case
>is take advantage of the returned number being an Int32, and use a logic
>operator on it.  The catch is that you either need to be able to use a
>range that's 2^n-1, rather than 0-4, or you need to do a little bit
>fancier ...
>
>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)
-- 
-- Marshall

Marshall Clow     Idio Software   <mailto:[EMAIL PROTECTED]>
Hey! Who messed with my anti-paranoia shot?

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

Reply via email to