GetTickCount returns a 32 bit value. Could be anything, more or less. Let's see that.
xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
Each 'x' is one bit. Could be 0, could be 1.
You are then bitwise ANDing the number with
lstrlenA(str)
, which has the value 17. Let's see that in binary as well:
0000 0000 0000 0000 0000 0000 0001 0001
Let's see what a bitwise AND of those two values looks like:
0000 0000 0000 0000 0000 0000 000x 000x
It's zero everywhere, except in two places. When you bitwise AND two values, the result will be zero in every bit unless both input bits are 1.
x can be 0 or 1, so here are all the possible values of
increment
:
0001 0001 = 17
0001 0000 = 16
0000 0001 = 1
0000 0000 = 0
So we can clearly see that your random number generator has only four possible output values.
I am trying to generate a random number from one to the length of the string |
Your code, as you can see, is not doing anything remotely like that.