| ??? 12/26/03 05:34 Read: times |
#61407 - RE: Random number from 1 to 8 Responding to: ???'s previous message |
Hallo Mahmood,
I'm not sure, whether I understood you correctly. But if you want to fabricate random numbers '1', '2', '3', ... , '8', then you should divide rand() by 32,768, not 32,767. Why? Because with your formula you will get random number '8' only, when rand() = 32,767. This would not deliver numbers '1' to '8' with equal probability. Number of occurances of '8' would be much smaller than that of the other numbers. I would use the following formula: Divide rand() by 32,768, multiply by eight, add one and take the integer, means neglect everything behind the decimal point. Or, a bit simpler: Divide rand() by 4096, add one and take the integer. Bye, Kai |



