Really interesting code there. Thanks for posting it. What is the source? If I understand correctly it creates a loaded d20 dice where the weighting of the faces is derived from a complex comparison of offense and mitigation.
It seems mitigation gets scaled to the attacker's offense by subtracting the average between the attacker's offence and the defender's mitigation from the mob's mitigation, producing the adjusted scaled mitigation. I supose this is to make it so that while it is possible to squelch a weaker' mob's mitigation to some degree, they always have at least some chance to mitigate?
The code then does some comparisons of the adjusted mitigation value to offence to create a multiplier based on offense.
The next bit I'm not sure of, but the presence of a mean and standard deviation along with other values suggests a normal distribution is created, the mean for which is set based on the offence mitigation comparisons.
This explains why we have spikes counts of the lower and highest hit values. As a normal distribution has been generated, theoretically there are no limits to the highest and lowest values of d generated, so the values which are out of bounds are getting lumped into the dice as rolls of 1 or 20 (i.e. min or max damage).
Can stats/code fans verify I'm understanding this snippet of code correctly? Are there any details where you can provide deeper understanding either? My interpretation seems to match my previously reported understanding, but I admit my interpretation was likely coloured by my existing beliefs.
Edit: Here is the code DSM kindly shared, which I interpret as creating a loaded d20 damage roll with the faces weighted by a complex comparison of offence and mitigation transformed into a normal distribution.