First time someone brings that up, actually it has nothing to do with the last refill value. The script is just basically getting a new refill number every time it checked how many cannonballs are in the cannon, so if you are at 29 cannonballs there is a 1/30 chance that you refill, at 28 theres a 2/30 chance etc, so it naturally skews a bit more thowards refilling earlier or around half.
There is obviously still randomness involved but i feel like that seems more realistic compared to refilling at every single number of shots left equally.