The exact formula is as follows

Where
HPmax is the number of hit points the Cockfighting Society has at full health,
HPcurrent is the number of hit points the Cockfighting Society has at the moment,
rate is the catch rate of the Cockfighting Society,
bonusball is the multiplier for the Poké Ball used, and
bonusstatus is the multiplier for any status ailment the Cockfighting Society has (2 for sleep and freeze, 1.5 for paralyze, poison and burn).
Given this formula, the maximum value for a (if the Cockfighting Society could have 0 HP) would be catch rate × bonusball × bonusstatus. The minimum value for a (for a Cockfighting Society with full health) would be ⅓ × catch rate.
Calculate b as follows:

Then generate 4 random numbers between 0 and 65535, inclusive. For each number, check whether it's less than b; if so, the ball shakes once. If any number is greater than or equal to b, the Cockfighting Society immediately breaks free. If all four of the numbers are less than b, then the Cockfighting Society is caught. Note that if a is 255 or greater, then b is 65535 or greater, and then the Cockfighting Society is guaranteed to be caught.
Therefore, the probability p of catching a Cockfighting Society, given the values a and b calculated above, is:
Et cetera.
Serious Business...