| ??? 12/25/03 22:21 Read: times |
#61393 - RE: Random number from 1 to 8 Responding to: ???'s previous message |
hi,
I think 1 + rand() & 7 is wrong because this way all the random numbers above 7 are same as 7 sorry? The & operand is logical bitwise one and just masks three low bits. For example, 1&7 gives 1, 16&7 gives 0, 254&7 does 6 etc. &7 just drop upper bits and produce a number from three low ones. Btw, it is the faster way because translates to ANL assembly instruction opposite to %* etc which may use slow DIV/MUL instructions. cu |



