Users browsing this thread: 6 Guest(s)
Breakable Tools - Need Help
07-07-2021, 11:38 AM
I know it's not the point of this thread, but there's no way this is correct:
$4B5A sets the accumulator to a random number from 0–255.
ANDing that with 42 doesn't give you a 1/42 chance. It gives you a 1/8 chance.
2A has 3 bits that are 1. ANDing sets all bits in the accumulator to except those 3. If the accumulator is now 0, the branch will be taken. The chance of those 3 bits being 0 is 1/2^3 = 1/8.
ANDing like this only works when the denominator is a power of 2. If you actually want a 1/42 chance, you need to do this:
Code:
JSR $4B5A
AND #$2A ; 1/42 chance of breaking
BNE no_break
$4B5A sets the accumulator to a random number from 0–255.
ANDing that with 42 doesn't give you a 1/42 chance. It gives you a 1/8 chance.
2A has 3 bits that are 1. ANDing sets all bits in the accumulator to except those 3. If the accumulator is now 0, the branch will be taken. The chance of those 3 bits being 0 is 1/2^3 = 1/8.
ANDing like this only works when the denominator is a power of 2. If you actually want a 1/42 chance, you need to do this:
Code:
LDA #$2A
JSR $4B65 ; set A to a random number between 0 and A-1
BNE no_break
« Next Oldest | Next Newest »
Users browsing this thread: 6 Guest(s)