> Now, for my proposed solution. First, I mask off the bits I don't need.
> The idea is that if I take a subset of the bits, these will be uniformly
> random (all values equally likely). For example, to get a value from 0
> to 99, you'd mask off bits to get a uniform random number between 0 and
> 127. Since the original generator generated all values between 0 and
> 32767 exactly once before repeating, the masked values between 0 and 127
> will each be generated exactly 8 times each before repeating. So, it is
> indeed uniform. Now, if I throw away those values > 127, I should have a
> uniform distribution for the remaining values because they all occur
> equally often. My probability theory is pretty rusty, so maybe I'm
> confused.
well.. most random functions operate like this:
---
/**
* Generate a random number.
*
* @param seed value, 0 to use existing seed.
* @return random number.
*/
UInt16
DeviceRandom(UInt32 seed)
{
if (seed != 0) globals->randomSeed = seed;
globals->randomSeed = (0x015A4E35L * globals->randomSeed) + 1;
return (globals->randomSeed >> 16) & 0x7FFF;
}
---
so, you should be able to generate some "logic" of the mapping..
(this
if time is not an issue, why not take the whole number generated, and
then take X bits out, form a smaller word (divisible by 2) and do what
Peter said.
ie: result ->> 16 bit integer
X X X X X X X X X X X X X X X X <-- result
| | | | | | | | <-- use these bits
you shuold write a few sample apps, and plot the distribution using
a static seed value. maybe you can find a nice method / bit choosing
that generates an equal distribution for each number.
how important is your randomness? :)
// az
[EMAIL PROTECTED]
http://www.ardiri.com/ <--- free games!
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/