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.

-Ken

On Sun, 2003-01-26 at 17:21, Geoffrey wrote:
> After have a look to the Palm OS Referemce, I know that SysRandom can
> gen a random number from 0 to sysRandomMax.
> 
> But no matter what I change to the value of sysRandomMax at file
> \sdk\include\Core\System\SysUtils.h, the result have no different before
> change.
> 
> I had change the sysRandomMax to in order to gen a number from 0 to 4:
> #define sysRandomMax  0x0004
> 
> But the sysRandomMax still give me a large number. How can I slove it?


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

Reply via email to