I'm not sure that I see the difference. Taking 0x7FFF as an example, and
assuming a true random value (not the case, but assuming...) the values 0-67
are slightly more likely than 68-99 since, as you mention, the max is not
evenly divisible.
However, I don't see how truncating and retrying as you describe will
correct this. Retrying if you are greater than 100 will not clip off the
extra occurrence of 0-67, since they will pass the test and be included as
legal values. It seems that 68-99 would continue to appear 0x7F times, but
0-67 0x80 times over the range.
I suppose if you are worried about the extra probability you could retry
whenever the value is greater than 32700, then modulo. Personally, I don't
worry about it, since the probability error in the random function itself is
already pretty high.
-jjf
-----Original Message-----
From: Peter Epstein [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 06, 2000 3:51 PM
To: Palm Developer Forum
Subject: RE: SysRandom and sysRandomMax
At 03:45 PM 11/6/2000, Fitzpatrick, Joe wrote:
>You can't, you have to turn it into a smaller number yourself. Use the
>modulo (%) operator (ex. <random> % 100 will return a value from 0-99).
I think modulo 100 won't retain a perfect uniform distribution since
sysRandomMax + 1 is not a multiple of 100. Probably better would be to mask
off the bits you don't need (&& 0xFF in this case), then test if the value
is within range (< 100 in this case), and retry if not.
--
Peter Epstein
Palm Inc. Developer
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/