| ??? 12/27/03 20:07 Read: times |
#61449 - RE: Random number from 1 to 8 Responding to: ???'s previous message |
Thanks Kai, but I think if I mask the upper 5 bits as Oleg pointed out, I will get my random numbers from 1 to 8 with equal distribution without the need for division.
Hallo Mahmood, I have experimented some time ago with random numbers fabricated by this modulo concept (three parameters), which is often used in higher program languages. And I can tell you, that some sets of parameters can show a certain repeatability at the least significant bits, even when total numbers show good pseudo randomness. So, just masking upper sigificant bits can result in tremendous decrease of randomness! It need not, but it can. E.g.: Pseudo random routines can produce numbers, where the least significant bit is changing from 0 to 1 and vice versa, all the time. If you now mask all the upper significant bits, you don't get a random number of 0 to 1, but an always alternating series of 0,1,0,1,0,1,0,... So, with one higher program language this masking can work, with others, which use a different modulo approach with different parameters, not. This should be kept in mind. By the way, decrease of randomness is also possible by other manipulations of random numbers, e.g. by dividing. A good routine of fabricating random numbers will be highly immune against this, but it cannot be guaranteed. Bad routines can show a heavy repeatability, means a heavy loss of pseudo randomness, when reducing degrees of freedom. Don't forget, that 15 bits are involved with 0 to 32767 random numbers, but only 3 bits with 1 to 8 random numbers! Manipulation of random numbers, which reduces degrees of freedom can totally destroy pseudo randomness! So, you should always make a test, when switching from one computer or program language to another, whether pseudo randomness actually satisfies!! Good luck, Kai |



