Geoffrey wrote:
You are right. But the SysRandom() function isn't "truely" random either. Finding truely random numbers is a pretty serious CompSci issue and you can probably find a lot more info on it elsewhere on the web.If I mod it with 5, then the result will be 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1 (each have same probability to gen), then the chance of the "0" and "1" return is 3/12 and the other is 2/12. The probaility will not be same for each value!
In the meantime, you might try this for a quick and reasonably random way for finding the roll of a die. Break the number you want into pieces of 2^n - 1 like:I am now try to give a random result of a dice, it is not fair that some number have more probaility to return!
union breaker {
UInt16 input;
struct {
UInt16 a:2;
UInt16 b:1;
UInt16 c:1;
} output;
};
UInt16 RollDie() {
union breaker b;
b.input = SysRandom( TimGetTicks() );
return ( b.output.a + b.output.b + b.output.c ) + 1;
}
I'm not sure about the syntax but something like that. You can't dynamically change the number of sides on the die, but you could write multiple functions depending on how many sides you wanted.
matt
--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
