Escape chance

I wanted to know what it the escape chance or/and how it is calculated, would help me a lot
the escape chance is based on the relative difference between party and enemy AGI, and increased by each failed escape attempt.
Thanks
Here's the function in case it helps.

Code:
BattleManager.makeEscapeRatio = function() {
    this._escapeRatio = (0.5 * $gameParty.agility()) / $gameTroop.agility();
};

The agility() functions just calculate the average of their respective group's speed, so it's basically:

averagePartyAgility / averageEnemyAgility / 2

This is then checked against a random number between 0 and 0.9999999. If the random number is lower, escape is successful. If higher, escape fails and the ratio is increased by +0.1. Here's a few examples

Example 1:
- Party: 200 average agility
- Enemies: 100 average agility
- Ratio is 1, so the party can escape successfully every single time on the first try

Example 2:
- Party: 100 average agility
- Enemies: 100 average agility
- Ratio is 0.5, so the party has a 50% chance to escape.
- If they fail to escape, the ratio is increased to 0.6, or 60%
- If they fail again, it becomes 0.7, 0.8, 0.9, etc until finally reaching 1, guaranteeing escape.

Edit: Also worth noting is the fact that buffing your party members to escape during battle doesn't help because the ratio is a snapshot taken at the start of the battle. So if you cast Haste to increase your party's speed and Slow to debuff the enemies' speed, it won't do anything even if the values for both effects are insanely large. Which is kind of dumb.

Original thread: https://forums.rpgmakerweb.com/threads/escape-chance.133738/