How does exactly the weight of random encounter works? (seriously)

Hi guys, I has been working in a map using random encounters for different weights (priorities) in different regions.

I made a region with 3 different enemies, they all with weight = 5
upload_2019-2-26_22-2-23.png

(sorry, it is in spanish)

Following this thread, and this one and the program documentation (on neocities),
upload_2019-2-26_22-7-30.png


They all say, my 3 monster should have the same chance to appear in a battle. but this is WRONG.

The first monster in the list (Grupo de babas) appears almost all the time (something like 90%)
The second monster (Medusa de jalea*2) appear every 10 battles (10%)
The third monster (Medusa de celos), does not show at all.

Changing the numbers to 5-4-3 or 3-4-5 give me the same result, so the weight (Priorid.) is not working or is not how the documentation says.

QUESTIONS:
  • Does anyone know the real formula?
  • Is there a script to do this work in a better way?
Thank you! ♥
This is the ruby code (RGSS3)
Code:
  def make_encounter_troop_id
    encounter_list = []
    weight_sum = 0
    $game_map.encounter_list.each do |encounter|
      next unless encounter_ok?(encounter)
      encounter_list.push(encounter)
      weight_sum += encounter.weight
    end
    if weight_sum > 0
      value = rand(weight_sum)
      encounter_list.each do |encounter|
        value -= encounter.weight
        return encounter.troop_id if value < 0
      end
    end
    return 0
  end
And this is the JS code (MV)
Code:
Game_Player.prototype.makeEncounterTroopId = function() {
    var encounterList = [];
    var weightSum = 0;
    $gameMap.encounterList().forEach(function(encounter) {
        if (this.meetsEncounterConditions(encounter)) {
            encounterList.push(encounter);
            weightSum += encounter.weight;
        }
    }, this);
    if (weightSum > 0) {
        var value = Math.randomInt(weightSum);
        for (var i = 0; i < encounterList.length; i++) {
            value -= encounterList[i].weight;
            if (value < 0) {
                return encounterList[i].troopId;
            }
        }
    }
    return 0;
};
From what I've understand, it behaves like a roulette selection.
A simplified model would be something like this
Fitness_proportionate_selection_example.png


EDIT: An even more simplified model
Roulette-wheel-selection.png


Theoretically, the documentation is correct.
If it behaves differently, maybe something is interfering it? Does it works the same in the blank project?
Thank you so much for your help!

You are right. I made a new project and tested the same values and they appears randomly.

So it is something wrong with my project, I installed a lot of Yanfly plugins! D:

I will try checking which one is giving me this problem.
Plus you know, it could simply be RNG playing with you.. Just because the 3 outcomes have the same probability, it doesnt mean that they will always behave like it or even close to it. Probabilities only come true normally if we have infinite trials.
@stramin
I once wrote a topic about this in the (long gone) user blogs on this site.
Luckily for you, someone else restored that old topic, follow the link in my signature to my old blogs and look for the topic on weight calculations.

EDIT:
As for your problem, have you any plugin that changes region behaviour?
Because the default random tables are locked to region (which means any specific encounter is only available for the random table if the player steps on the given region ID), but if you have plugins that redirect how the regions are handled that might mess up with that table.
it could simply be RNG playing with you

I thought about it, I was testing for a while before posting (maybe 20 tests), but maybe you are right because Is working better today...

@stramin
I once wrote a topic about this in the (long gone) user blogs on this site.
As for your problem, have you any plugin that changes region behaviour?

Thank you for your help!

And yes... I have a lot of plugins...

Original thread: https://forums.rpgmakerweb.com/threads/how-does-exactly-the-weight-of-random-encounter-works-seriously.106148/